Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 0f968e4

Browse files
authored
Merge pull request #2 from agno-agi/improvement/routes
2 parents bf40ae7 + e6bc33e commit 0f968e4

File tree

4 files changed

+8
-193
lines changed

4 files changed

+8
-193
lines changed

.github/workflows/validate.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ jobs:
3333
with:
3434
python-version: ${{ matrix.python-version }}
3535

36+
- name: Create a virtual environment
37+
run: uv venv --python ${{ matrix.python-version }}
38+
3639
- name: Install the project
37-
run: uv pip sync requirements.txt
40+
run: uv pip sync requirements.txt && uv pip install ruff && uv pip install mypy
3841

3942
- name: Format with ruff
4043
run: uv run ruff format .

api/routes/agents.py

Lines changed: 2 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from enum import Enum
2-
from typing import Any, AsyncGenerator, Dict, List, Optional
2+
from typing import AsyncGenerator, List, Optional
33

44
from agno.agent import Agent
5-
from agno.storage.agent.session import AgentSession
65
from fastapi import APIRouter, HTTPException, status
76
from fastapi.responses import StreamingResponse
87
from pydantic import BaseModel
@@ -64,7 +63,7 @@ class RunRequest(BaseModel):
6463
session_id: Optional[str] = None
6564

6665

67-
@agents_router.post("/{agent_id}/run", status_code=status.HTTP_200_OK)
66+
@agents_router.post("/{agent_id}/runs", status_code=status.HTTP_200_OK)
6867
async def run_agent(agent_id: AgentType, body: RunRequest):
6968
"""
7069
POST /agents/{agent_id}/run
@@ -101,190 +100,3 @@ async def run_agent(agent_id: AgentType, body: RunRequest):
101100
# For advanced use cases, we should yield the entire response
102101
# that contains the tool calls and intermediate steps.
103102
return response.content
104-
105-
106-
@agents_router.get("/{agent_id}/sessions", response_model=List[str])
107-
async def get_agent_session_ids(agent_id: AgentType, user_id: Optional[str] = None):
108-
"""
109-
GET /agents/{agent_id}/sessions
110-
111-
Returns all session IDs for a specific agent and user.
112-
113-
Args:
114-
agent_id: The agent type
115-
user_id: Optional user ID
116-
117-
Returns:
118-
List[str]: List of session identifiers
119-
"""
120-
logger.debug(f"GetAgentSessionsRequest: agent_id={agent_id}, user_id={user_id}")
121-
return get_agent(user_id=user_id, agent_id=agent_id).storage.get_all_session_ids()
122-
123-
124-
@agents_router.get("/{agent_id}/sessions/{session_id}", response_model=Optional[AgentSession])
125-
async def get_agent_session(agent_id: AgentType, session_id: str, user_id: Optional[str] = None):
126-
"""
127-
GET /agents/{agent_id}/sessions/{session_id}
128-
129-
Retrieves details about a specific agent session.
130-
131-
Args:
132-
agent_id: Agent ID
133-
session_id: The session ID to retrieve
134-
user_id: Optional user ID
135-
136-
Returns:
137-
AgentSession or None if not found
138-
"""
139-
logger.debug(f"GetAgentSessionRequest: agent_id={agent_id}, session_id={session_id}, user_id={user_id}")
140-
141-
try:
142-
agent: Agent = get_agent(session_id=session_id, user_id=user_id, agent_id=agent_id)
143-
return agent.read_from_storage()
144-
except Exception as e:
145-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Session not found: {str(e)}")
146-
147-
148-
@agents_router.get("/{agent_id}/sessions/{session_id}/messages", response_model=List[Dict[str, Any]])
149-
async def get_session_messages(agent_id: AgentType, session_id: str, user_id: Optional[str] = None):
150-
"""
151-
GET /agents/{agent_id}/sessions/{session_id}/messages
152-
153-
Retrieves the messages for a specific agent session.
154-
155-
Args:
156-
agent_id: Agent ID
157-
session_id: The session ID to retrieve history for
158-
user_id: Optional user ID
159-
160-
Returns:
161-
List of message objects representing the conversation history
162-
"""
163-
logger.debug(f"GetSessionHistoryRequest: agent_id={agent_id}, session_id={session_id}, user_id={user_id}")
164-
165-
try:
166-
agent: Agent = get_agent(session_id=session_id, user_id=user_id, agent_id=agent_id)
167-
# Load the agent from the database
168-
agent.read_from_storage()
169-
except Exception as e:
170-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Session not found: {str(e)}")
171-
172-
if agent.memory:
173-
return agent.memory.get_messages()
174-
else:
175-
return []
176-
177-
178-
@agents_router.delete("/{agent_id}/sessions/{session_id}", response_model=dict)
179-
async def delete_session(agent_id: AgentType, session_id: str, user_id: Optional[str] = None):
180-
"""
181-
DELETE /agents/{agent_id}/sessions/{session_id}
182-
183-
Deletes a specific agent session.
184-
"""
185-
logger.debug(f"DeleteSessionRequest: agent_id={agent_id}, session_id={session_id}")
186-
187-
try:
188-
agent: Agent = get_agent(user_id=user_id, agent_id=agent_id, session_id=session_id)
189-
agent.delete_session(session_id=session_id)
190-
return {"message": "Session deleted"}
191-
except Exception as e:
192-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Session not found: {str(e)}")
193-
194-
195-
class RenameSessionRequest(BaseModel):
196-
"""Request model for renaming a session"""
197-
198-
session_name: str
199-
200-
201-
@agents_router.patch("/{agent_id}/sessions/{session_id}/rename", response_model=dict)
202-
async def rename_session(
203-
agent_id: AgentType, session_id: str, body: RenameSessionRequest, user_id: Optional[str] = None
204-
):
205-
"""
206-
PATCH /agents/{agent_id}/sessions/{session_id}/rename
207-
208-
Renames a specific agent session.
209-
210-
Args:
211-
agent_id: Agent ID
212-
session_id: The session ID to rename
213-
body: Request containing the new session name
214-
user_id: Optional user ID
215-
216-
Returns:
217-
Updated session information
218-
"""
219-
logger.debug(
220-
f"RenameSessionRequest: agent_id={agent_id}, session_id={session_id}, session_name={body.session_name}"
221-
)
222-
223-
try:
224-
agent: Agent = get_agent(user_id=user_id, agent_id=agent_id, session_id=session_id)
225-
agent.rename_session(session_name=body.session_name)
226-
227-
return {
228-
"session_id": agent.session_id,
229-
"session_name": agent.session_name,
230-
}
231-
except Exception as e:
232-
# Use a more appropriate status code for errors that might not be "not found"
233-
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=f"Failed to rename session: {str(e)}")
234-
235-
236-
@agents_router.post("/{agent_id}/sessions/{session_id}/auto-rename", response_model=dict)
237-
async def auto_rename_session(agent_id: AgentType, session_id: str, user_id: Optional[str] = None):
238-
"""
239-
POST /agents/{agent_id}/sessions/{session_id}/auto-rename
240-
241-
Automatically renames a session using the LLM based on conversation context.
242-
243-
Args:
244-
session_id: The session ID to auto-rename
245-
user_id: Optional user ID
246-
agent_id: Optional agent type
247-
248-
Returns:
249-
Updated session information with the auto-generated name
250-
"""
251-
logger.debug(f"AutoRenameSessionRequest: agent_id={agent_id}, session_id={session_id}")
252-
253-
try:
254-
agent: Agent = get_agent(user_id=user_id, agent_id=agent_id, session_id=session_id)
255-
agent.auto_rename_session()
256-
257-
return {
258-
"session_id": agent.session_id,
259-
"session_name": agent.session_name,
260-
}
261-
except Exception as e:
262-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Failed to auto-rename session: {str(e)}")
263-
264-
265-
@agents_router.post("/{agent_id}/load-knowledge", status_code=status.HTTP_200_OK)
266-
async def load_knowledge(agent_id: AgentType, user_id: Optional[str] = None, recreate: bool = False):
267-
"""
268-
POST /agents/{agent_id}/load-knowledge
269-
270-
Loads the knowledge base for a specific agent. Please update the Agent Knowledge Base with the required data before calling this endpoint. Example: PDFUrlKnowledgeBase, CSVKnowledgeBase, etc.
271-
272-
Args:
273-
agent_id: The agent type
274-
user_id: Optional user ID
275-
recreate: Whether to recreate the knowledge base
276-
Returns:
277-
Confirmation message
278-
"""
279-
logger.debug(f"LoadKnowledgeRequest: agent_id={agent_id}, user_id={user_id}")
280-
281-
try:
282-
agent: Agent = get_agent(user_id=user_id, agent_id=agent_id)
283-
logger.debug(f"Agent: {agent.knowledge}")
284-
if agent.knowledge is not None:
285-
agent.knowledge.load(recreate=recreate)
286-
return {"message": "Knowledge Base Loaded"}
287-
except Exception as e:
288-
logger.error(f"Failed to load knowledge base: {str(e)}")
289-
# Consider more specific error handling here - not all exceptions should be 404
290-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Failed to load knowledge base: {str(e)}")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ readme = "README.md"
66
authors = [{ name = "Agno", email = "[email protected]" }]
77

88
dependencies = [
9-
"agno[aws]==1.1.9",
9+
"agno[aws]==1.1.13",
1010
"alembic",
1111
"beautifulsoup4",
1212
"duckduckgo-search",

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file was autogenerated by uv via the following command:
22
# ./scripts/generate_requirements.sh
3-
agno==1.1.9
3+
agno==1.1.13
44
agno-aws==0.0.1
55
agno-docker==0.0.1
66
alembic==1.13.3

0 commit comments

Comments
 (0)