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.
RetryAgentRun
StopAgentRun
AgentRunException
from agno.agent import Agent from agno.exceptions import RetryAgentRun from agno.models.openai import OpenAIChat from agno.utils.log import logger def add_item(agent: Agent, item: str) -> str: """将商品添加到购物清单。""" agent.session_state["shopping_list"].append(item) len_shopping_list = len(agent.session_state["shopping_list"]) if len_shopping_list < 3: raise RetryAgentRun( f"购物清单:{agent.session_state['shopping_list']}。购物清单最少需要 3 个商品。 " + f"请再添加 {3 - len_shopping_list} 个商品。", ) logger.info(f"购物清单现在是:{agent.session_state.get('shopping_list')}") return f"购物清单现在是:{agent.session_state.get('shopping_list')}" agent = Agent( model=OpenAIChat(id="gpt-4o-mini"), # 使用空的购物清单初始化会话状态 session_state={"shopping_list": []}, tools=[add_item], markdown=True, ) agent.print_response("添加牛奶", stream=True) print(f"最终会话状态:{agent.session_state}")
AGNO_DEBUG
True