Geek Out Time: Building a Multi-Agent Financial Advisor Copilot with AG2 (formerly AutoGen), OpenAI, and DeepSeek LLM
(Also on Constellar tech blog https://medium.com/the-constellar-digital-technology-blog/geek-out-time-building-a-multi-agent-financial-advisor-copilot-with-ag2-formerly-autogen-98acd2e4b54c)
The latest advancements in AG2 (formerly AutoGen) make it easier than ever to build multi-agent AI systems that go beyond simple chatbot interactions. With AG2, AI agents can collaborate, delegate tasks, and execute real-world functions — transforming the way we use AI for automation.
Unlike traditional chatbots that just provide answers, AG2 enables:
- Automated task execution — AI agents don’t just suggest actions; they take them.
- Seamless multi-agent collaboration — Different agents specialize in different tasks.
- Function calling with execution — AI can trigger backend functions dynamically.
In this Geek Out Time, I will walk through building a Financial Advisor Copilot, an AI-powered assistant that not only provides financial advice but also automates key actions such as:
- Sending birthday gifts and policy renewal reminders.
- Scheduling client meetings.
- Submitting claim forms.
This is all powered by OpenAI’s GPT-4o (or DeepSeek) using AG2’s latest function registration and execution capabilities.
What’s New in AG2? Smarter Function Execution
One of the biggest enhancements in AG2 is built-in function execution, eliminating the need for complex workarounds from previous AutoGen versions.
Key improvements:
? Native function execution with register_for_llm() – No manual function routing required. ? Seamless agent-to-agent delegation – Tasks are assigned to the right agent automatically. ? Modular architecture – Easily expand the system by adding more agents.
This makes AI far more powerful and actionable than just a chat-based assistant.
Multi-Agent Architecture: How It Works
The Financial Advisor Copilot consists of multiple specialized agents:
- Financial Advisor Agent (FA) — Primary user interaction agent, delegates tasks to others.
- Engagement Agent — Manages client interactions (birthday gifts, renewal reminders).
- Operations Agent — Handles scheduling and paperwork (meetings, claims).
- Execution Agent — Runs backend functions when needed.
Instead of following linear chatbot flows, this system intelligently selects the best agent for the task — making interactions feel natural and efficient.
Building the AI Copilot in Colab: Step-by-Step
1. Setting Up AG2 with OpenAI’s GPT-4o (or DeepSeek)
!pip install ag2
# Import necessary modules
import os
import random
from autogen import ConversableAgent, UserProxyAgent, GroupChat, GroupChatManager
# Set OpenAI API Key
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "sk-xxxxxxxxxx")
if not OPENAI_API_KEY:
raise ValueError("? OpenAI API Key is missing! Set it using os.environ['OPENAI_API_KEY'] = 'your-key'")
# Define LLM Configuration
llm_config = {
"config_list": [
{
"model": "gpt-4o",
"api_key": OPENAI_API_KEY,
}
],
"temperature": 0
}
To use DeepSeek instead:
llm_config = {
"config_list": [
{
"model": "deepseek-chat",
"api_key": "your-deepseek-api-key",
"base_url": "https://api.deepseek.com/v1",
}
],
"temperature": 0
}
Since DeepSeek follows OpenAI’s API format, it’s fully compatible.
2. Function Execution: Automating Financial Tasks
AG2 enables function execution, allowing AI agents to take action. Here are some key functions:
# Define our functions
def send_birthday_gifts():
"""
Send birthday gifts to clients with upcoming birthdays.
"""
sample_customers = [
{"name": "John Doe", "birthday": "Feb 26"},
{"name": "Jane Smith", "birthday": "Feb 28"},
{"name": "Sarah Williams", "birthday": "Feb 27"}
]
gifts = ["Gift basket", "Chocolate box", "Gift card"]
results = [f"? Sent {random.choice(gifts)} to {c['name']} (Birthday: {c['birthday']})" for c in sample_customers]
return "\n".join(results)
def send_renewal_reminders():
"""
Send policy renewal reminders to clients with upcoming renewals.
"""
sample_customers = [
{"name": "John Doe", "renewal": "March 15"},
{"name": "Jane Smith", "renewal": "April 20"},
{"name": "Sarah Williams", "renewal": "March 5"}
]
results = [f"? Sent renewal reminder to {c['name']} (Renewal date: {c['renewal']})" for c in sample_customers]
return "\n".join(results)
def schedule_client_meeting(client_name=None):
"""
Schedule a client meeting with the specified client.
If no client is specified, will schedule with a random client.
"""
if not client_name:
client_names = ["John Doe", "Jane Smith", "Sarah Williams"]
client_name = random.choice(client_names)
meeting_dates = [
"March 3 at 10:00 AM",
"March 4 at 2:00 PM",
"March 5 at 11:30 AM"
]
meeting_date = random.choice(meeting_dates)
return f"? Scheduled meeting with {client_name} on {meeting_date}"
def submit_claim_form(client_name=None, claim_type=None):
"""
Submit a claim form for the specified client and claim type.
If not specified, defaults will be used.
"""
if not client_name:
client_names = ["John Doe", "Jane Smith", "Sarah Williams"]
client_name = random.choice(client_names)
if not claim_type:
claim_types = ["Health", "Auto", "Home", "Life"]
claim_type = random.choice(claim_types)
claim_id = f"CLM-{random.randint(10000, 99999)}"
return f"? Submitted {claim_type} claim form for {client_name}. Claim ID: {claim_id}"
Create agents
# Create the user proxy agent for executing functions
user_proxy = UserProxyAgent(
name="ExecutorAgent",
human_input_mode="NEVER",
llm_config=False, # No LLM for the executor
)
# Create the specialist agents
fa_agent = ConversableAgent(
name="FinancialAdvisor",
system_message="""You are a financial advisor assistant. You answer general financial questions and direct specific tasks to the appropriate specialist:
- For client engagement tasks like sending birthday gifts or renewal reminders, defer to the EngagementAgent
- For operational tasks like scheduling meetings or claim forms, defer to the OperationAgent
- For product recommendations, you can handle these directly
Always be helpful, professional, and knowledgeable about financial matters.""",
llm_config=llm_config,
)
engagement_agent = ConversableAgent(
name="EngagementAgent",
system_message="""You assist with client engagement through birthday greetings, renewal reminders, and personalized check-ins.
You can:
1. Send birthday gifts to clients with upcoming birthdays
2. Send policy renewal reminders to clients
When asked about these tasks, use your tools rather than just describing what you would do.
Be warm, personable, and focused on strengthening client relationships.""",
llm_config=llm_config,
)
operation_agent = ConversableAgent(
name="OperationAgent",
system_message="""You assist with operational tasks like scheduling meetings and handling paperwork.
You can:
1. Schedule client meetings
2. Submit claim forms
When asked about these tasks, use your tools rather than just describing what you would do.
Be efficient and provide clear confirmations when tasks are completed.""",
llm_config=llm_config,
)
AG2 now allows direct function registration with agents:
# Register functions with their respective agents
# Engagement Agent Functions
@user_proxy.register_for_execution()
@engagement_agent.register_for_llm(description="Send birthday gifts to clients with upcoming birthdays")
def get_birthday_gifts(unused_param="unused"):
"""
Send birthday gifts to clients with upcoming birthdays.
"""
return send_birthday_gifts()
@user_proxy.register_for_execution()
@engagement_agent.register_for_llm(description="Send policy renewal reminders to clients with upcoming renewals")
def get_renewal_reminders(unused_param="unused"):
"""
Send policy renewal reminders to clients with upcoming renewals.
"""
return send_renewal_reminders()
# Operation Agent Functions
@user_proxy.register_for_execution()
@operation_agent.register_for_llm(description="Schedule a client meeting")
def get_client_meeting(client_name=None):
"""
Schedule a client meeting with the specified client.
Args:
client_name: The name of the client to schedule with. If not provided, a random client will be selected.
"""
return schedule_client_meeting(client_name)
@user_proxy.register_for_execution()
@operation_agent.register_for_llm(description="Submit a claim form for a client")
def get_claim_form(client_name=None, claim_type=None):
"""
Submit a claim form for a client.
Args:
client_name: The name of the client. If not provided, a random client will be selected.
claim_type: The type of claim (Health, Auto, Home, Life). If not provided, a random type will be selected.
"""
return submit_claim_form(client_name, claim_type)
This is a huge improvement over older AutoGen versions, which required manual intervention for function calls.
3. Multi-Agent Collaboration in AG2
We register the agents for automated collaboration:
# Create Group Chat with all agents
groupchat = GroupChat(
agents=[user_proxy, fa_agent, engagement_agent, operation_agent],
messages=[],
max_round=10, # Allow more rounds for complex conversations
)
# Create Group Chat Manager
manager = GroupChatManager(
groupchat=groupchat,
llm_config=llm_config,
)
If the user asks: “Send birthday giftsâ€, AG2:
- Routes the request to the engagement agent.
- Calls the send_birthday_gifts() function.
- Executes and confirms the action.
This means LLMs don’t just chat — they take action.
# Function to run the FA Copilot
def run_fa_copilot():
print("?? Financial Advisor Copilot Activated!")
print("?? Try asking about:")
print(" - Sending birthday gifts")
print(" - Sending renewal reminders")
print(" - Scheduling a client meeting")
print(" - Submitting a claim form")
print(" - Getting financial advice")
print("?? Type 'exit' or 'quit' to end the session.")
while True:
user_input = input("\n?? Question: ")
if user_input.lower() in ["exit", "quit"]:
print("?? Exiting FA Copilot. Goodbye!")
break
try:
# Initiate the chat with the manager
user_proxy.initiate_chat(
manager,
message=user_input,
max_turns=5 # Limit conversation turns to avoid excessive back-and-forth
)
except Exception as e:
print(f"?? Error: {e}. Please try again.")
# Start if running directly
if __name__ == "__main__":
run_fa_copilot()
else:
print("To start the Financial Advisor Copilot, run the run_fa_copilot() function")
Results: AI in Action
Running the FA Copilot produces the following interaction:
?? Financial Advisor Copilot Activated!
?? Try asking about:
- Sending birthday gifts
- Sending renewal reminders
- Scheduling a client meeting
- Submitting a claim form
- Getting financial advice
?? Type 'exit' or 'quit' to end the session.
?? Question: send birthday gifts
ExecutorAgent (to chat_manager):
send birthday gifts
--------------------------------------------------------------------------------
Next speaker: EngagementAgent
>>>>>>>> USING AUTO REPLY...
EngagementAgent (to chat_manager):
***** Suggested tool call (call_ZZmnYGjvJS7lpzxQ38JCJS9f): get_birthday_gifts *****
Arguments:
{}
***********************************************************************************
--------------------------------------------------------------------------------
Next speaker: ExecutorAgent
>>>>>>>> EXECUTING FUNCTION get_birthday_gifts...
Call ID: call_ZZmnYGjvJS7lpzxQ38JCJS9f
Input arguments: {}
ExecutorAgent (to chat_manager):
***** Response from calling tool (call_ZZmnYGjvJS7lpzxQ38JCJS9f) *****
? Sent Chocolate box to John Doe (Birthday: Feb 26)
? Sent Gift card to Jane Smith (Birthday: Feb 28)
? Sent Chocolate box to Sarah Williams (Birthday: Feb 27)
**********************************************************************
--------------------------------------------------------------------------------
Next speaker: FinancialAdvisor
>>>>>>>> USING AUTO REPLY...
FinancialAdvisor (to chat_manager):
The birthday gifts have been successfully sent to the clients. If you need further assistance, feel free to ask!
This proves AG2 can handle real-world automation — not just text responses.
Future Work: Expanding the AI Copilot
This is just the beginning. The roadmap for improvement includes:
- Making it more modular — Adding more agents for fraud detection, financial planning, and compliance.
- Expanding beyond function execution — Enhancing workflows to support multi-step task automation.
- Increasing extensibility — Connecting to external systems like CRMs, banking APIs, and finance platforms.
- Adding more AI-powered decision-making — Making the system more adaptive and intelligent.
The future of AI-powered automation is here, and AG2 is making it powerful, scalable, and fun to build.
Final Thoughts
AG2 enhances AI-driven automation by enabling the creation of intelligent multi-agent assistants. Whether using OpenAI’s GPT-4o or DeepSeek, AG2 equips developers with the tools to build AI systems that go beyond answering queries to executing real-world tasks.
This is just the start — stay tuned as I will add more… Enjoy the experiments and have fun.
I am using DALLE that comes with gpt 4o, included in my sub, though some ethical safeguards prevent generating certain images... There are many alternatives outside there now... Grok3 pretty impressive, in x though
Adaptive Backend Engineer | 5+ years of exp | Kotlin | Node.js | ACS (Australia Computer Society) Certified | Building Scalable Solutions // Make life easier with codes ?
2 周Hi Sir, i‘m curious. do you mind to share, what tools that you use to generate the images? ????