Quick Start
Install CLI first:
curl -fsSL https://install.acontext.io | shIntegrate Agno with Acontext for session persistence and task extraction
acontext create my-agno-project --template-path "python/agno-basic"
curl -fsSL https://install.acontext.io | shRun agent with Acontext
Complete example
import os
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools import tool
from acontext import AcontextClient
client = AcontextClient(
api_key=os.getenv("ACONTEXT_API_KEY"),
)
# If you're using self-hosted Acontext:
# client = AcontextClient(
# base_url="http://localhost:8029/api/v1",
# api_key="sk-ac-your-root-api-bearer-token",
# )
@tool
def get_weather(city: str) -> str:
"""Returns weather info for the specified city."""
return f"The weather in {city} is sunny"
agent = Agent(
name="Assistant",
model=OpenAIChat(id="gpt-4"),
instructions="You are a helpful assistant",
tools=[get_weather],
)
# Create session
session = client.sessions.create()
conversation = []
# User message
user_msg = {"role": "user", "content": "Plan a 3-day trip to Finland"}
conversation.append(user_msg)
client.sessions.store_message(session_id=session.id, blob=user_msg)
# Run agent
response = agent.run(conversation)
# Store response
assistant_msg = {"role": "assistant", "content": response.content}
conversation.append(assistant_msg)
client.sessions.store_message(session_id=session.id, blob=assistant_msg)
# Extract tasks
client.sessions.flush(session.id)
tasks = client.sessions.get_tasks(session.id)
for task in tasks.items:
print(f"Task: {task.data.task_description} | Status: {task.status}")
messages = client.sessions.get_messages(session_id)
conversation = messages.items
conversation.append({"role": "user", "content": "Continue from where we left off"})
response = agent.run(conversation)