Skip to content

Commit

Permalink
version update
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkulaga committed Jan 10, 2025
1 parent 8c2b00a commit d8ce06b
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 71 deletions.
4 changes: 2 additions & 2 deletions coding/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "just-agents-coding"
version = "0.4.7"
version = "0.4.8"
description = "Just Agents - Coding Components"
authors = [
"Alex Karmazin <karmazinalex@gmail.com>",
Expand All @@ -19,7 +19,7 @@ license = "MIT"

[tool.poetry.dependencies]
python = ">=3.10,<4.0"
just-agents-core = ">=0.4.7"
just-agents-core = ">=0.4.8"
llm-sandbox = ">=0.1.8"

[build-system]
Expand Down
30 changes: 6 additions & 24 deletions core/just_agents/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,9 @@ class ChatAgent(BaseAgent):
role: Optional[str] = Field(default=None, description="Defines the agent's persona or identity")
goal: Optional[str] = Field (default=None, description="Specifies the agent's broader objective.")
task: Optional[str] = Field (default=None, description="Describes the specific task the agent is responsible for.")
format: Optional[str] = Field (default=None, description="Describes the specific format the agent is responsible for.")


delegation_prompt: Optional[str] = Field(default="You can delegate your task by calling the delegate function to the following agents:", description="Defines the prompt for the delegation")
delegates: Optional[list[str, BaseAgent]] = Field(default_factory=dict, description="Defines the list of agents that this agent can delegate to with descriptions")


def _update_system_promptform_prompt(self):
# Create a prompt incorporating role, goal, task
prompt = (
f"You are a {self.role}.\n"
f"Your goal is to {self.goal}.\n"
f"Your task is to {self.task}.\n"
"Respond appropriately."
)
return prompt

def model_post_init(self, __context: Any) -> None:
# Call parent's post_init to maintain core functionality
Expand All @@ -330,14 +319,7 @@ def model_post_init(self, __context: Any) -> None:
self.system_prompt = self.system_prompt + "\n" + self.goal
if self.task is not None:
self.system_prompt = self.system_prompt + "\n" + self.task
if len(self.delegates) > 0:
self.system_prompt = self.system_prompt + "\n" + self.delegation_prompt
self.system_prompt = self.system_prompt + "\n" + "\n".join([f"{agent.shortname}: {agent.description}" for agent in self.delegates.values()])
self.clear_memory()

@property
def delegates_dict(self) -> dict[str, BaseAgent]:
"""Returns a dictionary mapping agent shortnames to their corresponding BaseAgent instances"""
return {agent.shortname: agent for agent in self.delegates.values()}


if self.format is not None:
self.system_prompt = self.system_prompt + "\n" + self.format
self.memory.clear_messages()
self.instruct(self.system_prompt)
2 changes: 1 addition & 1 deletion core/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "just-agents-core"
version = "0.4.7"
version = "0.4.8"
description = "Just Agents - Base Package"
authors = [
"Alex Karmazin <karmazinalex@gmail.com>",
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/01_just_agents_colab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
}
],
"source": [
"!pip install just-agents-core==0.4.7"
"!pip install just-agents-core==0.4.8"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions examples/notebooks/02_sqlite_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
"Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (3.7.1)\n",
"Requirement already satisfied: distro<2,>=1.7.0 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (1.9.0)\n",
"Requirement already satisfied: httpx<1,>=0.23.0 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (0.27.2)\n",
"Requirement already satisfied: jiter<1,>=0.4.7 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (0.7.0)\n",
"Requirement already satisfied: jiter<1,>=0.4.8 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (0.7.0)\n",
"Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (1.3.1)\n",
"Requirement already satisfied: tqdm>4 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (4.66.6)\n",
"Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3.0.0,>=2.0.0->litellm>=1.51.0->just-agents) (0.7.0)\n",
Expand Down Expand Up @@ -312,8 +312,8 @@
}
],
"source": [
"!pip install just-agents-core==0.4.7\n",
"!pip install just-agents-examples==0.4.7"
"!pip install just-agents-core==0.4.8\n",
"!pip install just-agents-examples==0.4.8"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions examples/notebooks/03_coding_agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (3.7.1)\n",
"Requirement already satisfied: distro<2,>=1.7.0 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (1.9.0)\n",
"Requirement already satisfied: httpx<1,>=0.23.0 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (0.27.2)\n",
"Requirement already satisfied: jiter<1,>=0.4.7 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (0.7.1)\n",
"Requirement already satisfied: jiter<1,>=0.4.8 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (0.7.1)\n",
"Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (1.3.1)\n",
"Requirement already satisfied: tqdm>4 in /usr/local/lib/python3.10/dist-packages (from openai>=1.54.0->litellm>=1.51.0->just-agents) (4.66.6)\n",
"Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3.0.0,>=2.0.0->litellm>=1.51.0->just-agents) (0.7.0)\n",
Expand Down Expand Up @@ -156,8 +156,8 @@
}
],
"source": [
"!pip install just-agents-core==0.4.7\n",
"!pip install just-agents-examples==0.4.7"
"!pip install just-agents-core==0.4.8\n",
"!pip install just-agents-examples==0.4.8"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions examples/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "just-agents-examples"
version = "0.4.7"
version = "0.4.8"
description = "Just Agents - Examples code"
authors = ["Alex Karmazin <karmazinalex@gmail.com>"]
maintainers = ["Anton Kulaga <antonkulaga@gmail.com>"]
Expand All @@ -12,11 +12,11 @@ license = "MIT"

[tool.poetry.dependencies]
python = ">=3.10,<4.0"
just-agents-core = ">=0.4.7"
just-agents-tools = ">=0.4.7"
just-agents-coding = ">=0.4.7"
just-agents-web = ">=0.4.7"
just-agents-router = ">=0.4.7"
just-agents-core = ">=0.4.8"
just-agents-tools = ">=0.4.8"
just-agents-coding = ">=0.4.8"
just-agents-web = ">=0.4.8"
just-agents-router = ">=0.4.8"
docker = ">=7.1.0"

[tool.poetry.group.dev.dependencies]
Expand Down
30 changes: 15 additions & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "just-agents"
version = "0.4.7"
version = "0.4.8"
description = "Just Agents - A lightweight, straightforward library for LLM agents that focuses on simplicity over unnecessary abstractions."
authors = [
"Alex Karmazin <karmazinalex@gmail.com>",
Expand All @@ -26,12 +26,12 @@ just-agents-router = { path = "router", develop = true }
just-agents-examples = { path = "examples", develop = true }

[tool.poetry.group.publish.dependencies]
just-agents-core = "0.4.7"
just-agents-tools = "0.4.7"
just-agents-coding = "0.4.7"
just-agents-web = "0.4.7"
just-agents-router = "0.4.7"
just-agents-examples = "0.4.7"
just-agents-core = "0.4.8"
just-agents-tools = "0.4.8"
just-agents-coding = "0.4.8"
just-agents-web = "0.4.8"
just-agents-router = "0.4.8"
just-agents-examples = "0.4.8"

[tool.poetry.group.dev.dependencies]
pytest = ">=8.3.4"
Expand Down
4 changes: 2 additions & 2 deletions router/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "just-agents-router"
version = "0.4.7"
version = "0.4.8"
description = "Just Agents - Router Components"
authors = [
"Newton Winter <isoutthere@gmail.com>",
Expand All @@ -18,7 +18,7 @@ license = "MIT"

[tool.poetry.dependencies]
python = ">=3.10,<4.0"
just-agents-core = ">=0.4.7"
just-agents-core = ">=0.4.8"

[tool.poetry.group.dev.dependencies]
pytest = ">=8.3.4"
Expand Down
66 changes: 63 additions & 3 deletions tests/test_chat_agent.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import pprint
from dotenv import load_dotenv
from just_agents.base_agent import ChatAgent
from just_agents.patterns.chain_of_throught import ChainOfThoughtAgent
import just_agents.llm_options
from just_agents.llm_options import LLAMA3_3, OPENAI_GPT4oMINI
from pprint import pprint

from just_agents.tools.db import sqlite_query
import pytest
import requests
import os
from pathlib import Path
from pycomfort.logging import to_nice_stdout
from pydantic import BaseModel, Field
from typing import Optional

to_nice_stdout()
db_path = Path("tests/data/open_genes.sqlite")


@pytest.fixture(scope="session")
def open_genes_db() -> Path:
"""Downloads the open_genes.sqlite database if not present and returns the path"""
Expand Down Expand Up @@ -39,14 +45,15 @@ def open_genes_db() -> Path:
return db_path



def test_quering(open_genes_db):
load_dotenv(override = True)

agent = ChatAgent(role="helpful agent which knows how operate with databases",
goal=f"help users by using SQL syntax to form comands to work with the {open_genes_db} sqlite database",
task="formulate appropriate comands to operate in the given database.",
tools=[sqlite_query],
llm_options=just_agents.llm_options.LLAMA3_3)
llm_options=LLAMA3_3)


response = agent.query("Show me all tables in the database")
Expand All @@ -62,4 +69,57 @@ def test_quering(open_genes_db):
]

for table in expected_tables:
assert table.lower() in response.lower(), f"Expected table '{table}' not found in response"
assert table.lower() in response.lower(), f"Expected table '{table}' not found in response"



class AgentResponse(BaseModel):
user_question: str = Field(..., description="The original question asked by the user")
answer: Optional[str] = Field(default="", description="Agent's initial answer or analysis")
delegate_to: Optional[str] = Field(default="", description="Name of the agent to delegate to, empty if no delegation")
question: Optional[str] = Field(default="", description="Question to delegate to another agent, empty if no delegation")
final_answer: Optional[str] = Field(default="", description="Final answer to the user's question, empty if pending delegation")

class Config:
json_schema_extra = {
"example": {
"user_question": "What genes extend lifespan?",
"answer": "This requires database access to analyze lifespan data",
"delegate_to": "agent_db",
"question": "SELECT * FROM lifespan_change WHERE species='mouse' ORDER BY lifespan_change DESC",
"final_answer": ""
}
}

@pytest.mark.skip(reason="Temporarily skipping this test")
def test_delegation():

agent_db = ChatAgent(role="helpful agent which knows how operate with databases",
goal=f"help users by using SQL syntax to form comands to work with the {db_path} sqlite database",
task="formulate appropriate comands to operate in the given database.",
tools=[sqlite_query],
llm_options=OPENAI_GPT4oMINI
)

ponder_agent = ChatAgent(
role="helpful agent which will only distribute the tasks to it's calling list and make minimal suggestions",
goal="help users by guiding them to appropriate instances that will answer their questions",
task=f"You are generalist agent which can delegate tasks to other agents, so far you only know agent_db which can run database queries on your behalf.",
format="""all your answers you represent solely as JSON object without any text either beore or after it. The format is the following:
{
"user_question": "question",
"answer": "your answer",
"delegate_to": "agent_name",
"question": "question_to_delegate",
"final_answer": "final answer to the question"
} If you do not delegate then delegate_to and question should be empty. if you are ready to answer the question then final_answer should be your answer, if not it must be empty""",
llm_options=OPENAI_GPT4oMINI
)

for i in range(3):
result = ponder_agent.query_structural(
"Interventions on which genes extended mice lifespan most of all? Search all the relevant tables in the open-genes sqlite and only for mouse", paarser=type[AgentResponse])
if result["delegate_to"] == "agent_db":
result = agent_db.query(result["question"])
print("\nQuery Result:") # Add a header for clarity
pprint(result)
Loading

0 comments on commit d8ce06b

Please sign in to comment.