Agents
Learn how to create agents with your prompts
Overview
Agents enable your prompts to run steps autonomously until a task is completed.
A regular prompt runs as a single step in a conversation. For more complex workflows, you can use Chains to set a specific sequence of steps for the AI to follow. However, certain tasks require the AI to be more flexible, improvising and adapting to the user’s input and the tool’s response in ways that Chains cannot achieve.
By defining a prompt as an “Agent”, the AI will automatically keep thinking and running tools until the task is completed, automatically adapting to the circumstances.
Syntax
Defining a prompt as an Agent is simple. Just add the type: agent
option to the prompt configuration, and specify their task as you would in a regular prompt.
Available tools
Agents can use all the tools available in Latitude, just like regular prompts. Having a selection of tools at their disposal is particularly useful, as the AI can then decide which ones to use and when, in order to complete the task.
Learn more about how to define tools in the Tools guide.
In this example, the AI identifies the need for a Location ID to retrieve the weather, but it only has the location name. To address this, the AI decides on a course of action. It uses the get_location_id
tool to obtain the ID, then utilizes the get_weather
tool to get the forecast, and finally returns the result to the user.
Response schema
You can define the structure of an agent’s final response by specifying its response schema. This is defined by using the JSON Schema option in the prompt configuration.
Predefined steps
Agents will run multiple steps autonomously until the task is completed. However, you can still use <step>
tags into the prompt to define specific steps the AI must follow before starting the autonomous process.
In this example, the first two steps will always be executed, and the AI will then proceed autonomously to complete the task, deciding what to do in each following step by itself.
Limiting steps
The AI will run autonomously until it decides the task is complete, based on your prompt. It can perform as many steps as necessary. To prevent infinite loops, you can set a limit on the number of steps using the maxSteps
option in the prompt configuration. By default, the limit is set to 20
, and you can change this configuration up to 150
.
Exceeding this limitation will result in an error and stop the agent from running further.
Running Agents
Agent prompts can be executed in exactly the same way as regular prompts. It will return a series of events that represent the AI’s thought process and the tools it uses to complete the task as a sequence of steps, just like with regular Chains, and eventually end with a final response.
Just using the run
API endpoint, or prompt.run
method from the SDK, and specify the prompt path and parameters as regular.
Learn more about how the API or the SDK Integrations.