Skip to content

Commit a3f8cb1

Browse files
committed
add second example, patch openai tool init
1 parent 97e1d34 commit a3f8cb1

File tree

8 files changed

+2042
-8
lines changed

8 files changed

+2042
-8
lines changed

examples/0-simple/src/main.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22
from agents.ada import Ada
33

44
agent = Ada(client=AnthropicLLM())
5-
prompt = "Name five fruit that start with the letter a."
65

7-
print(prompt)
8-
response = agent.generate_text(prompt)
9-
print(response.content)
6+
def chat(prompt):
7+
print(":USER:")
8+
print(prompt)
9+
print("\n"*3)
10+
response = agent.generate_text(prompt)
11+
print(":ADA:")
12+
print(response.content)
13+
print("\n"*3)
14+
15+
print("\n"*2)
16+
chat("Name five fruit that start with the letter a.")
17+
# Ada has a few tools, this is one of them (todo: link)
18+
chat("Get the repo structure of the current directory.")
19+
# agents store history in-memory by default,
20+
# they can be configured to work with other storage backends like postgres, mongo, etc...
21+
chat("Summarize our conversation in 10 words.")
22+
23+

examples/1-two-agents/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
start:
2+
poetry run python src/main.py

examples/1-two-agents/poetry.lock

Lines changed: 1949 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/1-two-agents/pyproject.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[tool.poetry]
2+
name = "ada-example-1-two-agents"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Will Beebe"]
6+
packages = [
7+
{include = "*", from="src"},
8+
]
9+
10+
[tool.poetry.dependencies]
11+
python = "^3.11"
12+
# ada-python = "^0.2.0"
13+
ada-python = {path = "../../", develop = true}
14+
15+
[tool.poetry.dev-dependencies]
16+
pytest = "^8.1.1"
17+
18+
[tool.pytest.ini_options]
19+
testpaths = ["tests"]
20+
21+
[tool.ruff]
22+
select = ["E", "F", "W", "I001"]
23+
ignore = ["E501", "F541"]
24+
fixable = ["W", "I001"]
25+
26+
[build-system]
27+
requires = ["poetry-core"]
28+
build-backend = "poetry.core.masonry.api"

examples/1-two-agents/src/main.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from abcs.anthropic import AnthropicLLM
2+
from abcs.openai import OpenAILLM
3+
from agents.aristotle import Aristotle
4+
from agents.plato import Plato
5+
6+
aristotle = Aristotle(client=AnthropicLLM())
7+
# other agents don't have to be from other providers,
8+
# but they can be. (todo: link)
9+
plato = Plato(client=OpenAILLM())
10+
chat_rounds = 3
11+
12+
def chat(prompt):
13+
for i in range(chat_rounds):
14+
print(f":ROUND {i} / {chat_rounds}:")
15+
response = aristotle.generate_text(prompt)
16+
prompt = response.content
17+
print(":Aristotle:")
18+
print(response.content)
19+
print("\n"*1)
20+
21+
response = plato.generate_text(prompt)
22+
prompt = response.content
23+
print(":Plato:")
24+
print(response.content)
25+
print("\n"*1)
26+
27+
28+
prompt = """I'm studying for an exam about Plato.
29+
I want to role play as Plato to test my knowledge.
30+
Can you act as Aristotle and challenge my core beliefs?
31+
"""
32+
print("\n"*2)
33+
print(":USER:")
34+
print(prompt)
35+
print("\n"*2)
36+
chat(prompt)
37+
38+
39+

src/abcs/anthropic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
import os
3-
from pprint import pprint
43
from typing import Any, Dict, List, Optional
54

65
import anthropic
@@ -109,7 +108,7 @@ def call_tool(
109108
],
110109
}
111110
logger.debug("\n"*20)
112-
logger.debug(pprint(past_messages + [tool_message]))
111+
logger.debug(f"{past_messages + [tool_message]}")
113112
logger.debug("\n"*20)
114113
response = self.client.messages.create(
115114
model=self.model,

src/abcs/openai.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def generate_text(
6262
combined_history = system_message + past_messages + [{"role": "user", "content": prompt}]
6363
logger.debug("Generating text with prompt: '%s'", prompt)
6464

65+
if tools is not None and len(tools) == 0:
66+
tools = None
67+
6568
try:
6669
logger.debug('\n'*10)
6770
logger.debug(combined_history)
@@ -119,7 +122,7 @@ def generate_text(
119122
model=self.model,
120123
messages=all_history,
121124
# might be able to remove
122-
# tools=tools,
125+
tools=tools,
123126
)
124127
return self._translate_response(response)
125128
except Exception as e:

src/agents/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class Agent(LLM):
1515
def __init__(self, client, tool_manager: ToolManager, system_prompt: str, tools=[], storage_manager: StorageManager = None):
1616
self.tools = tools
17-
logger.info("Initializing Agent with tools: %s and system prompt: '%s'", tools, system_prompt)
17+
logger.debug("Initializing Agent with tools: %s and system prompt: '%s'", tools, system_prompt)
1818
super().__init__(
1919
client=client,
2020
model=None,

0 commit comments

Comments
 (0)