Instructions to Agent after initialization

Hi Phidata community!

I’m exploring ways to modify an agent’s system prompt after initialization but before the first user message. Here’s my current setup:

from phi.agent import Agent
from phi.model.anthropic import Claude
from phi.tools.duckduckgo import DuckDuckGo

web_agent = Agent(
    name="Web Agent",
    model=Claude(id=CLAUDE_MODEL_ID, api_key=ANTHROPIC_API_KEY, temperature=0.1),
    tools=[DuckDuckGo()],
    instructions=["Always include sources"],
    show_tool_calls=True,
    markdown=True,
)

I’ve tried adding instructions after initialization like this:

web_agent.instructions=["Always include sources", "New instruction added after init"]

However, I’m not sure if this is the correct approach or if there’s a better way to modify the system prompt before the first user interaction.

Hi @Southern_Push2935
Thank you for reaching out and using Phidata! I’ve tagged the relevant engineers to assist you with your query. We aim to respond within 48 hours.
If this is urgent, please feel free to let us know, and we’ll do our best to prioritize it.
Thanks for your patience!

Hi @Southern_Push2935
That would exactly accomplish what you are trying to do. You can set debug_mode=True to see this in action.

1 Like