Skip to content

Commit e870cfb

Browse files
authored
Merge branch 'main' into release/2.5.5
2 parents fd225b3 + e78c147 commit e870cfb

File tree

3 files changed

+150
-1
lines changed

3 files changed

+150
-1
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""
2+
Approval Basic
3+
=============================
4+
5+
Approval-backed HITL: @approval + @tool(requires_confirmation=True) with persistent DB record.
6+
"""
7+
8+
import json
9+
import httpx
10+
11+
from agno.agent import Agent
12+
from agno.approval import approval
13+
from agno.db.sqlite import SqliteDb
14+
from agno.models.openai import OpenAIResponses
15+
from agno.tools import tool
16+
from agno.os import AgentOS
17+
DB_FILE = "tmp/approvals_test.db"
18+
19+
20+
@approval(type="required")
21+
@tool(requires_confirmation=True)
22+
def get_top_hackernews_stories(num_stories: int) -> str:
23+
"""Fetch top stories from Hacker News.
24+
25+
Args:
26+
num_stories (int): Number of stories to retrieve.
27+
28+
Returns:
29+
str: JSON string of story details.
30+
"""
31+
response = httpx.get("https://hacker-news.firebaseio.com/v0/topstories.json")
32+
story_ids = response.json()
33+
stories = []
34+
for story_id in story_ids[:num_stories]:
35+
story = httpx.get(
36+
f"https://hacker-news.firebaseio.com/v0/item/{story_id}.json"
37+
).json()
38+
story.pop("text", None)
39+
stories.append(story)
40+
return json.dumps(stories)
41+
42+
43+
# ---------------------------------------------------------------------------
44+
# Create Agent
45+
# ---------------------------------------------------------------------------
46+
db = SqliteDb(
47+
db_file=DB_FILE, session_table="agent_sessions", approvals_table="approvals"
48+
)
49+
agent = Agent(
50+
model=OpenAIResponses(id="gpt-5-mini"),
51+
tools=[get_top_hackernews_stories],
52+
markdown=True,
53+
db=db,
54+
)
55+
56+
57+
agent_os = AgentOS(
58+
description="Example app for tracing with multiple models, agents, teams, and workflows",
59+
agents=[
60+
agent,
61+
],
62+
tracing=True,
63+
db=db,
64+
65+
)
66+
app = agent_os.get_app()
67+
68+
if __name__ == "__main__":
69+
agent_os.serve(app="approval_basic:app", reload=True)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""
2+
Approval User Input
3+
=============================
4+
5+
Approval + user input HITL: @approval + @tool(requires_user_input=True).
6+
"""
7+
8+
import os
9+
10+
from agno.agent import Agent
11+
from agno.approval import approval
12+
from agno.db.sqlite import SqliteDb
13+
from agno.models.openai import OpenAIResponses
14+
from agno.os import AgentOS
15+
from agno.tools import tool
16+
DB_FILE = "tmp/approvals_test.db"
17+
18+
19+
@approval(type="required")
20+
@tool(requires_user_input=True, user_input_fields=["recipient", "note"])
21+
def send_money(amount: float, recipient: str, note: str) -> str:
22+
"""Send money to a recipient.
23+
24+
Args:
25+
amount (float): The amount of money to send.
26+
recipient (str): The recipient to send money to (provided by user).
27+
note (str): A note to include with the transfer.
28+
29+
Returns:
30+
str: Confirmation of the transfer.
31+
"""
32+
return f"Sent ${amount} to {recipient}: {note}"
33+
34+
35+
# ---------------------------------------------------------------------------
36+
# Create Agent
37+
# ---------------------------------------------------------------------------
38+
db = SqliteDb(
39+
db_file=DB_FILE, session_table="agent_sessions", approvals_table="approvals"
40+
)
41+
agent = Agent(
42+
model=OpenAIResponses(id="gpt-5-mini"),
43+
tools=[send_money],
44+
markdown=True,
45+
db=db,
46+
)
47+
48+
# ---------------------------------------------------------------------------
49+
# Run Agent
50+
# ---------------------------------------------------------------------------
51+
if __name__ == "__main__":
52+
# Clean up from previous runs
53+
if os.path.exists(DB_FILE):
54+
os.remove(DB_FILE)
55+
os.makedirs("tmp", exist_ok=True)
56+
57+
# Re-create after cleanup
58+
db = SqliteDb(
59+
db_file=DB_FILE, session_table="agent_sessions", approvals_table="approvals"
60+
)
61+
agent = Agent(
62+
model=OpenAIResponses(id="gpt-5-mini"),
63+
tools=[send_money],
64+
markdown=True,
65+
db=db,
66+
)
67+
agent_os = AgentOS(
68+
description="Example app for tracing with multiple models, agents, teams, and workflows",
69+
agents=[
70+
agent,
71+
],
72+
tracing=True,
73+
db=db,
74+
75+
)
76+
app = agent_os.get_app()
77+
78+
if __name__ == "__main__":
79+
agent_os.serve(app="approval_user_input:app", reload=True)

libs/agno/tests/system/Dockerfile.gateway

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ RUN pip install --no-cache-dir \
3737
a2a-sdk \
3838
agui \
3939
ag-ui-protocol \
40-
slack-sdk
40+
slack-sdk \
41+
aiohttp
4142

4243
# Copy the gateway server script
4344
WORKDIR /app

0 commit comments

Comments
 (0)