Skip to main content
Context engineering is the process of designing and controlling the information (context) that is sent to language models to guide their behavior and outputs. In practice, building context comes down to one question: “Which information is most likely to achieve the desired outcome?” The context of an Agno agent consists of the following:
  • System message: The system message is the main context that is sent to the agent, including all additional context
  • User message: The user message is the message that is sent to the agent.
  • Chat history: The chat history is the history of the conversation between the agent and the user.
  • Additional input: Any few-shot examples or other additional input that is added to the context.

System message context

The following are some key parameters that are used to create the system message:
  1. Description: A description that guides the overall behaviour of the agent.
  2. Instructions: A list of precise, task-specific instructions on how to achieve its goal.
  3. Expected Output: A description of the expected output from the Agent.
The system message is built from the agent’s description, instructions, and other settings.
Will produce the following system message:
By default, instructions are not wrapped in <instructions> tags. If you prefer to wrap instructions in XML tags (for example, when using models that benefit from XML structure), set use_instruction_tags=True:

System message Parameters

The Agent creates a default system message that can be customized using the following agent parameters: See the full Agent reference for more information.

How the system message is built

Lets take the following example agent:
Below is the system message that will be built:
This example is exhaustive and illustrates what is possible with the system message, however in practice you would only use some of these settings.

Additional Context

You can add additional context to the end of the system message using the additional_context parameter. Here, additional_context adds a note to the system message indicating that the agent can access specific database tables.

Tool Instructions

If you are using a Toolkit on your agent, you can add tool instructions to the system message using the instructions parameter:
These instructions are injected into the system message after the <additional_information> tags.

Agentic Memories

If you have enable_agentic_memory set to True on your agent, the agent gets the ability to create/update user memories using tools. This adds the following to the system message:

Agentic Knowledge Filters

If you have knowledge enabled on your agent, you can let the agent choose the knowledge filters using the enable_agentic_knowledge_filters parameter. This will add the following to the system message:
Learn about agentic knowledge filters in more detail in the knowledge filters section.

Set the system message directly

You can manually set the system message using the system_message parameter. This will ignore all other settings and use the system message you provide.
Some models via some model providers, like llama-3.2-11b-vision-preview on Groq, require no system message with other messages. To remove the system message, set build_context=False and system_message=None. Additionally, if markdown=True is set, it will add a system message, so either remove it or explicitly disable the system message.

User message context

The input sent to the Agent.run() or Agent.print_response() is used as the user message.

Additional user message context

You can add additional context to the user message using the following agent parameters: The following agent parameters configure how the user message is built:
  • add_knowledge_to_context
  • add_dependencies_to_context
The user message that is sent to the model will look like this:
See dependencies for how to do dependency injection for your user message.

Chat history

If you have database storage enabled on your agent, session history is automatically stored (see sessions). You can now add the history of the conversation to the context using add_history_to_context.
This will add the history of the conversation to the context, which can be used to provide context for the next message. See more details on sessions.

Managing Tool Calls

The max_tool_calls_from_history parameter can be used to add only the n most recent tool calls from history to the context. This helps manage context size and reduce token costs during agent runs. Consider the following example:
The model responds with the weather for the last 3 cities: Mumbai, Miami and New York. In this example:
  • Run 1-3: Model sees tool calls [1], [1,2], [1,2,3]
  • Run 4: Model sees tool calls [1,2,3,4]
  • Run 5: Model sees tool calls [2,3,4,5] (tool call 1 filtered out)
Important: max_tool_calls_from_history filters tool calls from the runs loaded by num_history_runs. Your database always contains the complete history.
See the full example for a complete demonstration.

Few-shot learning with additional input

You can add entire additional messages to your agent’s context using the additional_input parameter. These messages are added to the context as if they were part of the conversation history. You can give your agent examples of how it should respond (also called “few-shot prompting”):

Context Caching

Most model providers support caching of system and user messages, though the implementation differs between providers. The general approach is to cache repetitive content and common instructions, and then reuse that cached content in subsequent requests as the prefix of your system message. In other words, if the model supports it, you can reduce the number of tokens sent to the model by putting static content at the start of your system message. Agno’s context construction is designed to place the most likely static content at the beginning of the system message.
If you wish to fine-tune this, the recommended approach is to manually set the system message.
Some examples of prompt caching:

Developer Resources