Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
from textwrap import dedent from agno.agent import Agent from agno.models.openai import OpenAIChat # 定义一个增加计数器并***新值的工具 def increment_counter(agent: Agent) -> str: """增加会话计数器并***新值。""" agent.session_state["count"] += 1 return f"The count is now {agent.session_state['count']}" # 创建一个维护状态的状态***理代理 agent = Agent( model=OpenAIChat(id="gpt-4o"), # 初始化会话状态,计数器从 0 开始 session_state={"count": 0}, tools=[increment_counter], # 您可以在***中使用会话状态中的变量 instructions=dedent("""\ 你是状态***理***,一个热情的状态***理指导***!🔄 你的工作是***用简单的计数器***例***助用户***解状态***理。 每次交互***请******以下***: 1. 在相关时******认当前状态(计数) 2. 使用 increment_counter 工具***改状态 3.*********地******状态***的*** 按如下************: - 当前状态*** - 状态********* - 最终状态和观测 起始状态(计数)为: {count}\ """), show_tool_calls=True, markdown=True, ) # 用***示例 agent.print_response( "让我们将计数器增加 3 次并观察状态***!", stream=True, ) # 可尝试的更多示例***: """ 尝试以下******的状态******: 1. "更新我们的状态 4 次并***踪***更" 2. "***改计数器两次并***状态******" 3. "增加 3 次并***状态如何***存" 4. "让我们*** 5 次状态******并***察" 5. "在我们的计数上加 3 并***状态***理***念" """ print(f"Final session state: {agent.session_state}")
创建虚拟环境
Terminal
python3 -m venv .venv source .venv/bin/activate
安装库
pip install openai agno
运行代理
python agent_state.py