The ConversableAgent
is the fundamental building block of AG2 - think of it as both the brain and the personality of your AI system. With an LLM configuration providing its thinking power, a ConversableAgent can:
Every agent in your AG2 system is either a ConversableAgent
or built upon one, making it the most important class to understand.
Once you’ve set up your LLM configuration, creating a ConversableAgent
is straightforward:
Key Parameters
When creating a ConversableAgent
, there are several important parameters to consider:
name
: A unique identifier for your agentsystem_message
: Instructions that define the agent’s role, personality, and behaviorllm_config
: Configuration for the language model (can be passed directly or via context manager)The simplest way to interact with a ConversableAgent
is to use the run()
and process()
methods. Here’s a basic example:
???+ info
Why Two Steps: run()
and process()
You might wonder why we need to call both run()
and process()
to get results.
👉 Here’s what’s happening:
When you call run()
, it doesn’t immediately give you the final output.
Instead, it returns an iterator, a special object that holds a stream of events, messages, and metadata.
👉 Why? Because flexibility matters.
The workflow steps won’t actually start running until you iterate over this iterator. This design gives you full control and makes it easy to build things like:
👉 Okay — so what does process()
do?
process()
is a built-in helper method that takes care of iterating through those events for you.
It simulates a chat-like console experience — printing messages, handling user inputs, and making it feel like a live conversation.
👉 In short:
Use run()
and iterate over the events yourself when you want full control over the workflow’s events and how they are processed. 👉 Learn more about the run()
method here →
Use process()
along with run()
when you just want a quick, ready-to-go chat experience in the console.
Let’s create a simple financial agent using ConversableAgent
:
In this simple example:
max_turns=1
. This is one of the many ways to end a conversation. You can find more options in the Ending a chat.financial_compliance.py
)pip install ag2[openai]
python financial_compliance.py
When you run the code, you should see output similar to this:
This is just the beginning of what you can do with ConversableAgent
. In subsequent sections, we’ll expand this example to handle more complex financial tasks and interactions.
Now that you understand the basics of ConversableAgent
, it’s time to add some human oversight!
For financial compliance systems, a human review of flagged transactions adds an essential layer of security and compliance. In the next section, you’ll see how to build upon our simple example to create a more robust financial assistant with human oversight.
The ConversableAgent
is the fundamental building block of AG2 - think of it as both the brain and the personality of your AI system. With an LLM configuration providing its thinking power, a ConversableAgent can:
Every agent in your AG2 system is either a ConversableAgent
or built upon one, making it the most important class to understand.
Once you’ve set up your LLM configuration, creating a ConversableAgent
is straightforward:
Key Parameters
When creating a ConversableAgent
, there are several important parameters to consider:
name
: A unique identifier for your agentsystem_message
: Instructions that define the agent’s role, personality, and behaviorllm_config
: Configuration for the language model (can be passed directly or via context manager)The simplest way to interact with a ConversableAgent
is to use the run()
and process()
methods. Here’s a basic example:
???+ info
Why Two Steps: run()
and process()
You might wonder why we need to call both run()
and process()
to get results.
👉 Here’s what’s happening:
When you call run()
, it doesn’t immediately give you the final output.
Instead, it returns an iterator, a special object that holds a stream of events, messages, and metadata.
👉 Why? Because flexibility matters.
The workflow steps won’t actually start running until you iterate over this iterator. This design gives you full control and makes it easy to build things like:
👉 Okay — so what does process()
do?
process()
is a built-in helper method that takes care of iterating through those events for you.
It simulates a chat-like console experience — printing messages, handling user inputs, and making it feel like a live conversation.
👉 In short:
Use run()
and iterate over the events yourself when you want full control over the workflow’s events and how they are processed. 👉 Learn more about the run()
method here →
Use process()
along with run()
when you just want a quick, ready-to-go chat experience in the console.
Let’s create a simple financial agent using ConversableAgent
:
In this simple example:
max_turns=1
. This is one of the many ways to end a conversation. You can find more options in the Ending a chat.financial_compliance.py
)pip install ag2[openai]
python financial_compliance.py
When you run the code, you should see output similar to this:
This is just the beginning of what you can do with ConversableAgent
. In subsequent sections, we’ll expand this example to handle more complex financial tasks and interactions.
Now that you understand the basics of ConversableAgent
, it’s time to add some human oversight!
For financial compliance systems, a human review of flagged transactions adds an essential layer of security and compliance. In the next section, you’ll see how to build upon our simple example to create a more robust financial assistant with human oversight.