Agent
Easily implement LLM interactions extending the basic Agent class.
The two most important class Agent and RAG, are designed to be extended to create your specific agent implementation. They are rarely used as a standalone objects.
This ensure the portability of your agent because all the moving parts are encapsulated into a single entity that you can run wherever you want in your application.
Here is an example of the minimum implementation of an agent, in the following section we will add other features and capabilities:
As you can expect the first thing to do is define the LLM provider to be used for agent interactions.
If you want to pass external information to your agent you can pass them into the constructor.
Talk to the Agent
Now we are ready to run our first interaction to see the agent response:
Take a look at the AI Provider section to know about the supported provider as first party implementations, or learn how to implement a new one.
Add system instructions
Usually you need to condition the agent behavior toward a specific use case. The rules of how an agent should behave are provided in the system prompt. Let's implement the instructions method to set the predefined character of our agent:
We are ready to test how the agent respond to our message based on the new instructions.
Message
The agent always accept input as Message
class, and return Message instances.
As you saw in the example above we sent a UserMessage
instance to the agent and it responded with an AssistantMessage
instance. A list of assistant message and user message creates a chat.
We will learn more about ChatHistory later, but it's important to know that the unified interface for the agent input and response is the Message object.
Last updated