How to Use Python-A2A to create and connect to the financial agents with an agent-to-agent agent (A2A)

Python A2A Implementation agent-to-Agent-to-Agent (A2A) agent, which enabled AIs AI enables to use the application form, which is completed to complete the need for custom inclusion between services.
In this lesson, we will use the method based on the examining given by the Python-A2A library. With a simple @Ancelom including @SSIll? Decorations, you can describe your identity and your agent's behavior, while the library cares for the protocol management and the flow of messages.
This approach is ready to create a prompt manufacturing, focused agents without worrying about a low LOGIC.
To include leaning
To get started, you will need to include the Nthon-A2A library, which provides a clean Abstraction of constructing and running agents following A2 Protocol.
Open your terminal and run:
Creating agents
In this lesson, we will create two agents – one of the calculation of stock restoration based on investment, rate, time and time to fix the amount based on the increase in cash.
EMI AGENT (EMI_AGET.py)
from python_a2a import A2AServer, skill, agent, run_server, TaskStatus, TaskState
import re
@agent(
name="EMI Calculator Agent",
description="Calculates EMI for a given principal, interest rate, and loan duration",
version="1.0.0"
)
class EMIAgent(A2AServer):
@skill(
name="Calculate EMI",
description="Calculates EMI given principal, annual interest rate, and duration in months",
tags=["emi", "loan", "interest"]
)
def calculate_emi(self, principal: float, annual_rate: float, months: int) -> str:
monthly_rate = annual_rate / (12 * 100)
emi = (principal * monthly_rate * ((1 + monthly_rate) ** months)) / (((1 + monthly_rate) ** months) - 1)
return f"The EMI for a loan of ₹{principal:.0f} at {annual_rate:.2f}% interest for {months} months is ₹{emi:.2f}"
def handle_task(self, task):
input_text = task.message["content"]["text"]
# Extract values from natural language
principal_match = re.search(r"₹?(d{4,10})", input_text)
rate_match = re.search(r"(d+(.d+)?)s*%", input_text)
months_match = re.search(r"(d+)s*(months|month)", input_text, re.IGNORECASE)
try:
principal = float(principal_match.group(1)) if principal_match else 100000
rate = float(rate_match.group(1)) if rate_match else 10.0
months = int(months_match.group(1)) if months_match else 12
print(f"Inputs → Principal: {principal}, Rate: {rate}, Months: {months}")
emi_text = self.calculate_emi(principal, rate, months)
except Exception as e:
emi_text = f"Sorry, I couldn't parse your input. Error: {e}"
task.artifacts = [{
"parts": [{"type": "text", "text": emi_text}]
}]
task.status = TaskStatus(state=TaskState.COMPLETED)
return task
# Run the server
if __name__ == "__main__":
agent = EMIAgent()
run_server(agent, port=4737)
The EMI Calculator agent is made up of the Python-A2A library and follows the inspector-based approach. Up, we use @Ancelom The decoration is to describe the name of the agent, description, and version. This regulates agent to be able to communicate with A2 Protocol.
Inside in class, explaining one skill using the @SSSIL?l Decoration. This ability, called The_miMake real standing calculation using a regular formula. The formula takes three parameters: Loan principal, the value of the year's interest, and loan time in months. We change the year average into this month's level and use it to install a monthly EMI.
This page Hand_task The way the agent's core. It receives a user's installation message, issuing appropriate numbers using normal ordinary speeches, and has transferred to calculator_ememi.
Finally, at the bottom of the file, we present an agent using the Run_Sever () work in Durban 4737Make it ready to receive A2A-Comolic messages. The project keeps the agent simple, Modar, and easy to extend the skills more skills.
Ment of Inflation (Ovlation_agent.py)
from python_a2a import A2AServer, skill, agent, run_server, TaskStatus, TaskState
import re
@agent(
name="Inflation Adjusted Amount Agent",
description="Calculates the future value adjusted for inflation",
version="1.0.0"
)
class InflationAgent(A2AServer):
@skill(
name="Inflation Adjustment",
description="Adjusts an amount for inflation over time",
tags=["inflation", "adjustment", "future value"]
)
def handle_input(self, text: str) -> str:
try:
# Extract amount
amount_match = re.search(r"₹?(d{3,10})", text)
amount = float(amount_match.group(1)) if amount_match else None
# Extract rate (e.g. 6%, 7.5 percent)
rate_match = re.search(r"(d+(.d+)?)s*(%|percent)", text, re.IGNORECASE)
rate = float(rate_match.group(1)) if rate_match else None
# Extract years (e.g. 5 years)
years_match = re.search(r"(d+)s*(years|year)", text, re.IGNORECASE)
years = int(years_match.group(1)) if years_match else None
if amount is not None and rate is not None and years is not None:
adjusted = amount * ((1 + rate / 100) ** years)
return f"₹{amount:.2f} adjusted for {rate:.2f}% inflation over {years} years is ₹{adjusted:.2f}"
return (
"Please provide amount, inflation rate (e.g. 6%) and duration (e.g. 5 years).n"
"Example: 'What is ₹10000 worth after 5 years at 6% inflation?'"
)
except Exception as e:
return f"Sorry, I couldn't compute that. Error: {e}"
def handle_task(self, task):
text = task.message["content"]["text"]
result = self.handle_input(text)
task.artifacts = [{
"parts": [{"type": "text", "text": result}]
}]
task.status = TaskStatus(state=TaskState.COMPLETED)
return task
if __name__ == "__main__":
agent = InflationAgent()
run_server(agent, port=4747)
This organization is helping to calculate how much the amount provided in the future after preparing inflation. It uses a structure based on the same article given by the Python-A2A library. This page @Ancelom Decoration describes the Metadata of the representative, and @SSIll? The nomina registers the main idea under the word “inflation.”
This page Hold_inx The way in which the principal processing occurs. Releasing the amount, rate of inflation, and the number of years from user installation using normal ordinary speeches. If all three values, it uses a regular future formula to calculate the fixed amount of inflation:
A converted amount = Amount × (1 + 100) average ^ years.
If any missing amount, the agent returns quickly mentioned by the helpful user's what has given, including the example. This page Hand_task The work is all connected with taking a user's message, passing from skill service, and returns the redesigned result of the user.
Finally, the agent was presented using Run_Sever () port 4747Make it ready to manage A2A questions.
Creating a Agent Network
First Run Agents Two Different Terminals
python inflation_agent.py
Each of these people express the end of API to relax (eg for EMIs, inflation) using A2A Protocol. They listen to the incoming activities (such as “Count the EMI of ₹ 2,00,000 …”) and respond to the answers to the text.
Now, we will add these two agents to our network
from python_a2a import AgentNetwork, A2AClient, AIAgentRouter
# Create an agent network
network = AgentNetwork(name="Economics Calculator")
# Add agents to the network
network.add("EMI", "")
network.add("Inflation", "")
Next we will build a router in straight tests in the best agent. This is the basic application of A2 protocol-describing the format of regular jobs so agents can be viewed alike, and the routers can make wise travelers using llms.
router = AIAgentRouter(
llm_client=A2AClient(" # LLM for making routing decisions
agent_network=network
)
Finally, we will ask agents
query = "Calculate EMI for ₹200000 at 5% interest over 18 months."
agent_name, confidence = router.route_query(query)
print(f"Routing to {agent_name} with {confidence:.2f} confidence")
# Get the selected agent and ask the question
agent = network.get_agent(agent_name)
response = agent.ask(query)
print(f"Response: {response}")
query = "What is ₹1500000 worth if inflation is 9% for 10 years?"
agent_name, confidence = router.route_query(query)
print(f"Routing to {agent_name} with {confidence:.2f} confidence")
# Get the selected agent and ask the question
agent = network.get_agent(agent_name)
response = agent.ask(query)
print(f"Response: {response}")
Look Infiins- inflation_agent.py, Network.Yynb including EMI_AGET.py. All credit for this study goes to research for this project. Also, feel free to follow it Sane and don't forget to join ours 100K + ml subreddit Then sign up for Our newspaper.

I am the student of the community engineering (2022) from Jamia Millia Islamia, New Delhi, and I am very interested in data science, especially neural networks and their application at various locations.
