Skip to main content

zagency

A framework for building AI agents with LLM integration, tool discovery, and comprehensive evaluation capabilities.

Installation

pip install zagency

For development:

pip install -e .

Quick Start

from zagency import Agent, LiteLLM, tool

class MyAgent(Agent):
    @tool
    def calculate(self, expression: str) -> float:
        """Evaluate a mathematical expression"""
        return eval(expression)
    
    def step(self, environment):
        # Agent logic here
        state = self.ingest_state(environment)
        if state.get("task"):
            result = self.invoke([{"role": "user", "content": state["task"]}])
            environment.update_state({"result": result}, agent=self)
        return {"status": "completed"}

# Initialize and run
lm = LiteLLM(model="gpt-4")
agent = MyAgent(lm)

Core Components

Agents

Base class for all agents with automatic tool discovery:

  • Inherit from Agent class
  • Implement step() method for agent logic
  • Use @tool decorator to expose methods to LLM
  • Access LLM through self.invoke()

Environments

State management between agents:

  • Environment: All agents share the same state
  • IsolatedEnvironment: Each agent has private state with shared globals
  • CodingEnvironment: Specialized for code editing tasks

Language Models

Built on LiteLLM for multi-provider support:

from zagency import LiteLLM

# Supports OpenAI, Anthropic, and more
lm = LiteLLM(model="gpt-4")
lm = LiteLLM(model="claude-3-opus")

Tools

Decorated methods automatically become LLM-callable:

@tool
def search_files(self, pattern: str) -> list:
    """Search for files matching pattern"""
    return Path(".").glob(pattern)

Evaluation Framework

Scorers

Evaluate different aspects of agent behavior:

  • AgentScorer: Internal metrics (tokens, decisions)
  • EnvironmentScorer: State changes
  • TraceScorer: End-to-end performance

Running Evaluations

from zagency.core import Evaluation

eval = Evaluation(
    name="my_eval",
    scorers=[MyScorer(), AnotherScorer()]
)

results = eval.run(
    agent=agent,
    environment_class=Environment,
    dataset=test_cases,
    max_steps_per_datum=50
)

Advanced Usage

Multi-Agent Systems

from zagency.handler import StepHandler

handler = StepHandler(environment)
handler.add_agent(agent1)
handler.add_agent(agent2)
handler.run(max_steps=100)

Custom Environments

class MyEnvironment(Environment):
    def get_state(self, agent=None):
        # Return state for requesting agent
        return self._state
    
    def update_state(self, updates, agent=None):
        # Handle state updates
        self._state.update(updates)

Project Structure

zagency/
├── core/
│   ├── agent.py          # Base Agent class
│   ├── environment.py    # Environment implementations
│   ├── lm.py            # Language model abstraction
│   ├── scorer.py        # Scoring system
│   └── evaluation.py    # Evaluation framework
├── environments/        # Specialized environments
├── handler/            # Agent orchestration
└── tests/             # Test suite

Key Features

  • Automatic tool discovery via decorators
  • Multi-LLM support through LiteLLM
  • Flexible state management with environments
  • Comprehensive evaluation framework
  • Token usage tracking and cost monitoring
  • Rich console output support

Dependencies

  • torch, litellm, rich, pydantic
  • whisper, pyannote.audio (for audio capabilities)
  • ffmpeg-python (for media processing)

Development

# Run tests
pytest tests/

# Build package
make build

# Clean artifacts
make cleanup

License

MIT License

Links

Metadata

Release files for zagency 0.6.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zagency 0.6.5
File Size Uploaded
zagency-0.6.5.tar.gz 23.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for zagency 0.6.5
File Interpreter ABI Platform
zagency-0.6.5-py3-none-any.whl Python 3 none any Details

Total release size: 50.1 kB

Release files / zagency-0.6.5.tar.gz

Download URL zagency-0.6.5.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d6ae1ad2d73609af5166fdf00cef585f430f4a24d5616cb416c1734d1b3e4cad
BLAKE2b-256 checksum
How to use checksums
f5aa615581aa89f20476ee758a1a272178c0704f7ce183d3a11d74c44ff84bf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Release files / zagency-0.6.5-py3-none-any.whl

Download URL zagency-0.6.5-py3-none-any.whl
Size 26.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae72c6bc9dfc3b291d98f75e1d5092ef57a996791ac429a45298835f989620c9
BLAKE2b-256 checksum
How to use checksums
e55eecbd5fed353b61c7dae28005558466deebf3f5f6664c6865ed94d7effc16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Release history Release notifications | RSS feed

This release

0.6.5 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page