Quick Start
Install Package
First, install the PraisonAI Agents package:pip install praisonaiagents sympy pint
Set API Key
Set your OpenAI API key as an environment variable in your terminal:export OPENAI_API_KEY=your_api_key_here
Create a file
Create a new file app.py with the basic setup:from praisonaiagents import Agent, Task, PraisonAIAgents
from praisonaiagents.tools import (
evaluate, solve_equation, convert_units,
calculate_statistics, calculate_financial
)
# Create math agent
math_agent = Agent(
role="Math Expert",
goal="Perform complex mathematical calculations",
backstory="Expert in mathematical computations and analysis",
tools=[
evaluate, solve_equation, convert_units,
calculate_statistics, calculate_financial
],
verbose=True
)
# Create a task
task = Task(
description="Calculate compound interest and statistical analysis",
expected_output="Detailed mathematical analysis",
agent=math_agent
)
# Create and start the agents
agents = PraisonAIAgents(
agents=[math_agent],
tasks=[task],
process="sequential",
verbose=2
)
# Start execution
agents.start()
Start Agents
Type this in your terminal to run your agents: Install Package
Install the PraisonAI package:pip install praisonai sympy pint
Set API Key
Set your OpenAI API key as an environment variable in your terminal:export OPENAI_API_KEY=your_api_key_here
Create a file
Create a new file agents.yaml with the basic setup:framework: praisonai
process: sequential
topic: perform mathematical analysis
roles:
mathematician:
backstory: Expert in mathematical computations and analysis.
goal: Perform complex mathematical calculations
role: Math Expert
tools:
- evaluate
- solve_equation
- convert_units
- calculate_statistics
- calculate_financial
tasks:
math_task:
description: Calculate compound interest and perform statistical analysis.
expected_output: Detailed mathematical analysis with results.
Start Agents
Type this in your terminal to run your agents:
Requirements
- Python 3.10 or higher
- OpenAI API key. Generate OpenAI API key here. Use Other models using this guide.
- sympy and pint packages (automatically installed when needed)
Understanding Math Agents
What are Math Agents?
Math agents are specialized AI agents that can:
- Evaluate mathematical expressions
- Solve equations and systems of equations
- Perform unit conversions
- Calculate statistical metrics
- Handle financial calculations
Features
Expression Evaluator
Evaluates mathematical expressions and formulas.
Equation Solver
Solves mathematical equations and systems.
Unit Converter
Converts between different units of measurement.
Statistical Calculator
Calculates statistical metrics and analysis.
Multi-Agent AI Math Analysis
Install Package
First, install the PraisonAI Agents package:pip install praisonaiagents
Set API Key
Set your OpenAI API key as an environment variable in your terminal:export OPENAI_API_KEY=your_api_key_here
Create a file
Create a new file app.py with the basic setup:from praisonaiagents import Agent, Task, PraisonAIAgents
from praisonaiagents.tools import (
evaluate, solve_equation, convert_units,
calculate_statistics, calculate_financial
)
# Create first agent for calculations
calculator = Agent(
role="Mathematical Calculator",
goal="Perform complex calculations and analysis",
backstory="Expert in mathematical computations",
tools=[evaluate, solve_equation, convert_units],
verbose=True
)
# Create second agent for statistics
statistician = Agent(
role="Statistical Analyst",
goal="Perform statistical analysis and interpretation",
backstory="Expert in statistical analysis",
tools=[calculate_statistics, calculate_financial],
verbose=True
)
# Create first task
calc_task = Task(
description="Calculate compound interest for $10000 at 5% for 3 years",
expected_output="Detailed interest calculation",
agent=calculator
)
# Create second task
stats_task = Task(
description="Analyze the monthly interest distribution",
expected_output="Statistical analysis of interest data",
agent=statistician
)
# Create and start the agents
agents = PraisonAIAgents(
agents=[calculator, statistician],
tasks=[calc_task, stats_task],
process="sequential"
)
# Start execution
agents.start()
Start Agents
Type this in your terminal to run your agents: Install Package
Install the PraisonAI package: Set API Key
Set your OpenAI API key as an environment variable in your terminal:export OPENAI_API_KEY=your_api_key_here
Create a file
Create a new file agents.yaml with the basic setup:framework: praisonai
process: sequential
topic: perform financial and statistical analysis
roles:
calculator:
backstory: Expert in mathematical computations and analysis.
goal: Perform complex calculations
role: Mathematical Calculator
tools:
- evaluate
- solve_equation
- convert_units
tasks:
calc_task:
description: Calculate compound interest for investment scenario.
expected_output: Detailed interest calculations.
statistician:
backstory: Expert in statistical analysis and interpretation.
goal: Analyze numerical data and patterns
role: Statistical Analyst
tools:
- calculate_statistics
- calculate_financial
tasks:
stats_task:
description: Analyze the monthly interest distribution.
expected_output: Statistical analysis report.
Start Agents
Type this in your terminal to run your agents:
Configuration Options
# Create an agent with advanced math configuration
agent = Agent(
role="Math Expert",
goal="Perform complex mathematical analysis",
backstory="Expert in mathematical computations",
tools=[
evaluate,
solve_equation,
convert_units,
calculate_statistics,
calculate_financial
],
verbose=True, # Enable detailed logging
llm="gpt-4o" # Language model to use
)
Troubleshooting
Expression Errors
If expressions are not evaluating:
- Check syntax and formatting
- Verify variable definitions
- Enable verbose mode for debugging
Calculation Issues
If calculations are incorrect:
- Review input formats
- Check unit compatibility
- Verify formula structure
Next Steps
For optimal results, ensure mathematical expressions and units are properly formatted for your specific use case.