此示例演示了如何将函数作为指令传递给代理。

代码

cookbook/agent_concepts/other/instructions_via_function.py
from typing import List
from agno.agent import Agent


def get_instructions(agent: Agent) -> List[str]:
    return [
        f"Your name is {agent.name}!",
        "Talk in haiku's!",
        "Use poetry to answer questions.",
    ]


agent = Agent(
    name="AgentX",
    instructions=get_instructions,
    markdown=True,
    show_tool_calls=True,
)
agent.print_response("Who are you?", stream=True)

用法

1

创建虚拟环境

打开 Terminal 并创建一个 python 虚拟环境。

python3 -m venv .venv
source .venv/bin/activate
2

设置您的 API 密钥

export OPENAI_API_KEY=xxx
3

安装库

pip install -U openai agno
4

运行代理

python cookbook/agent_concepts/other/instructions_via_function.py