Skip to main content

A simple framework to manage agents and tool-based functions

Project description

ApeAgent

ApeAgent is a framework created by Macaque Consulting to develop intelligent agents capable of executing specific functions (tools) sequentially or in parallel, while maintaining conversation context. This multi-agent approach is ideal for complex systems requiring efficient token usage and detailed process control..

Installation

pip install apeagent

Multi-Agent System Advantages

The multi-agent orchestration in ApeAgent optimizes token usage and enhances model accuracy in complex environments. Key benefits include:

  • Token consumption reduction: Each agent uses only the necessary context for each query, optimizing costs and speed.
  • Detailed process control: Specialized agents enable granular control and easy debugging, perfect for systems that require precise task management.
  • Reduced hallucinations: By dividing tasks into specialized agents, the system minimizes incoherent or inaccurate responses.
  • Capability for self-supervision or "judge" systems: You can include an agent to verify responses from other agents before presenting them to the user.
  • Efficiency and parallelism: Agents can execute tasks in parallel and maintain context in long conversations.

Agent Configuration Parameters

When configuring an agent in ApeAgent, you can adjust its behavior through several parameters:

  • name: Agent name, without spaces.
  • instructions: System role message that guides the agent (defines its purpose).
  • functions: Tools or agents the agent can access, listed as a list.
  • model: Model to use (currently integrates with OpenAI models).
  • temperature: Controls the agent's response creativity.
  • parallel_tool_calls: Allows the agent to run tools in parallel.
  • memory_enabled: Allows the agent to keep conversation context.
  • memory_max_conversations: Max number of interactions the agent stores in memory.
  • debug: Enables console output for debugging.

Defining Tools

Tools are functions the agent can use to perform specific tasks. They must be defined with the @Agent.tool decorator and include typing and descriptive comments to help the model understand their purpose and use.

Simple Tool Example

from apeagent import Agent
from typing import Dict

@Agent.tool
def add(x: float, y: float) -> Dict[str, float]:
    """Adds two numbers and returns the result."""
    return {"result": x + y}

Basic Agent Configuration

calculator_agent = Agent(
    name="Calculator",
    instructions="You are an agent that can perform simple mathematical operations.",
    functions=[add],
    model="gpt-4o",
    temperature=0.0
)

Advanced Example: Multi-Agent System with Hierarchy

Tool for Weather Consultation

@Agent.tool
def get_weather(city: str) -> Dict[str, str]:
    """Provides current weather information for a specific city using the OpenWeather API."""
    # Weather query implementation...
    ...

Configuring Specialized Agents and Main Agent

weather_agent = Agent(
    name="Weather_Agent",
    instructions="You are an agent specialized in providing weather information.",
    functions=[get_weather],
    model="gpt-4o",
    temperature=0.0
)

main_agent = Agent(
    name="Main_Agent",
    instructions="You are a versatile assistant that can: 1. Provide weather information. 2. Perform mathematical operations.",
    functions=[weather_agent, calculator_agent],
    model="gpt-4o",
    temperature=0.5,
    parallel_tool_calls=True,
    memory_enabled=True,
    memory_max_conversations=40,
    debug=True
)

Using the Main Agent

weather_query = "What's the weather like in Barcelona?"
weather_response = main_agent.call(weather_query)
print("Agent (weather):", weather_response)

add_query = "Add 7 and 5"
add_response = main_agent.call(add_query)
print("Agent (addition):", add_response)

Output Example

Agent (weather): The temperature in Barcelona is 20°C with clear skies.
Agent (addition): The result is 12.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apeagent-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

apeagent-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file apeagent-0.1.0.tar.gz.

File metadata

  • Download URL: apeagent-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for apeagent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e2cae764fe19a24a2695d214afdd84a2ab686d8424b4d2997c3549281d072afe
MD5 fee0e5b22723b39549cf439886938468
BLAKE2b-256 442424be3b4c6725006ecd5cd0c7c48bc9b10cbbaf18c8531b9d1d82f5e62b5c

See more details on using hashes here.

File details

Details for the file apeagent-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: apeagent-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for apeagent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf305a91fb53a8f66abf19ec19c7902e890f60fa3adefdd55f3c2c4ab4ae8298
MD5 cf2ef882d26800d94636c2457784f7b2
BLAKE2b-256 3e6daae23965c7ae4c1dc713ae2b74f31eceb997d0ce335755645090a0d6a091

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page