Agents
Create autonomous agents that can use tools, reason, and complete complex tasks over multiple steps.
Latitude Agents are an advanced prompt type that enables AI models to operate autonomously, breaking down complex tasks, using tools, and reasoning through multiple steps until a final goal is achieved.
Unlike simple prompts or even Chains which follow predefined steps, Agents can dynamically decide their next action based on the context and available tools.
Defining an Agent
To turn a prompt into an Agent, simply add type: agent
to its configuration block:
How the Agent Loop Works
When an Agent prompt is run:
- Goal Understanding: The agent analyzes the initial prompt to understand the overall task or goal.
- Planning (Implicit): It internally plans the first step needed to move towards the goal.
- Action: It decides whether to: a. Call a Tool: If it needs external information or functionality, it requests a tool call. b. Generate Response: If it has enough information or needs to ask a clarifying question, it generates text.
- Observation: If a tool was called, it receives the tool’s response.
- Reasoning: Based on the goal, previous steps, and new observations (tool responses), it reasons about the next action needed.
- Repeat: Steps 3-5 repeat until the agent determines the original goal is fully accomplished.
- Final Answer: The agent provides the final result.
This loop allows the agent to adapt its strategy, handle errors, and utilize tools effectively.
Using Tools Within Agents
Agents become truly powerful when combined with Tools. Provide the agent with a set of relevant tools, and it will decide which ones to use and when.
In this example, the agent might:
- Realize it needs a location ID for
get_weather
. - Call
get_location_id
withlocation_name
. - Receive the
location_id
. - Call
get_weather
with the obtainedlocation_id
. - Receive the weather data.
- Formulate and return the final answer to the user.
Defining the Final Output (Schema)
You can guide the agent’s final output by specifying a response schema
using JSON Schema:
The agent will work towards fulfilling the task and then structure its final response according to the schema.
Predefined Steps
While agents operate autonomously, you can provide initial instructions or force specific actions using <step>
tags. The agent will execute these predefined steps first before entering its autonomous loop.
Limiting Agent Iterations
To prevent agents from running indefinitely (e.g., getting stuck in loops), you can limit the maximum number of steps (tool calls + LLM responses) using the maxSteps
configuration option (default: 20, max: 150).
If the limit is reached before the goal is completed, the agent run will terminate with an error.
Running Agents
Agents are run just like any other prompt using the API or SDKs. The response will typically be a stream of events detailing the agent’s thought process, tool calls, and final answer.
Subagents
You can make any prompt have access to other agents in your project by using the agents
configuration option. This allows you to create a hierarchy of agents, where tasks are delegated to subagents with specific responsibilities.
The main prompt will have access to running the subagent prompt as if it was a tool. This allows you to structure complex tasks into smaller, manageable sub-tasks performed by different agents.
Next Steps
- Explore Latitude Tools that agents can use.
- Test your agents in the Playground.
- Learn about Evaluations to assess agent performance.