Skip to main content

Lightweight multi-agent AI pipeline framework with decorator-based API

Project description

agentflow

PyPI version Python 3.10+ License: MIT

Lightweight multi-agent AI pipeline framework. Define agents with decorators, wire them into pipelines, stream events in real-time.

  • Decorator-based - Define agents as simple async functions
  • Async-first - Built on asyncio, no sync bottlenecks
  • Event streaming - Real-time pipeline monitoring via async generators
  • Provider agnostic - Works with any OpenAI-compatible API (OpenAI, Groq, Together, Ollama, etc.)
  • Minimal deps - Just openai + pydantic

Install

pip install agentflow-py

Quick Start

import asyncio
from agentflow import Agent, Pipeline, LLM

# 1. Configure LLM (any OpenAI-compatible provider)
llm = LLM(
    model="llama-3.3-70b-versatile",
    base_url="https://api.groq.com/openai/v1",
    api_key="your-api-key",
)

# 2. Define agents with decorators
@Agent(name="researcher", role="Research Analyst")
async def researcher(task: str, context: dict) -> str:
    return f"Research this topic thoroughly: {task}"

@Agent(name="writer", role="Content Writer")
async def writer(task: str, context: dict) -> str:
    research = context["researcher"]
    return f"Write an article based on:\n{research}"

# 3. Build pipeline
pipe = Pipeline(llm=llm)
pipe.add(researcher)
pipe.add(writer, depends_on=["researcher"])

# 4. Run
async def main():
    result = await pipe.run("AI in Healthcare")
    print(result.output)
    print(f"Tokens: {result.total_tokens}")

asyncio.run(main())

Event Streaming

Stream real-time events as agents execute:

async for event in pipe.stream("AI in Healthcare"):
    if event.type == "agent_start":
        print(f"{event.agent} started...")
    elif event.type == "agent_complete":
        print(f"{event.agent} done ({event.data['tokens']} tokens)")
    elif event.type == "pipeline_complete":
        print(f"Total: {event.data['total_tokens']} tokens")

Pipeline Results

Access individual agent results:

result = await pipe.run("AI in Healthcare")

# Final output (last agent)
print(result.output)

# Individual agent results
research = result.get("researcher")
print(research.output)
print(research.tokens_used)
print(research.duration)

# Totals
print(result.total_tokens)
print(result.total_duration)

Advanced: Class-Based Agents

For complex agents that need custom logic:

from agentflow import BaseAgent, AgentResult

class CustomAgent(BaseAgent):
    def __init__(self):
        super().__init__(name="custom", role="Custom Processor")

    async def execute(self, task, context, llm):
        # Custom logic here
        response = await llm.generate([
            {"role": "system", "content": f"You are a {self.role}."},
            {"role": "user", "content": task},
        ])
        return AgentResult(
            agent=self.name,
            output=response["content"],
            tokens_used=response["tokens"],
            duration=response["duration"],
        )

pipe.add(CustomAgent())

Supported Providers

Any OpenAI-compatible API works:

# OpenAI
llm = LLM(model="gpt-4o-mini", api_key="sk-...")

# Groq (free tier)
llm = LLM(model="llama-3.3-70b-versatile",
           base_url="https://api.groq.com/openai/v1",
           api_key="gsk_...")

# Ollama (local)
llm = LLM(model="llama3", base_url="http://localhost:11434/v1")

# Together AI
llm = LLM(model="meta-llama/Llama-3-70b-chat-hf",
           base_url="https://api.together.xyz/v1",
           api_key="...")

Examples

License

MIT

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

agentflowkit-0.1.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentflowkit-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentflowkit-0.1.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for agentflowkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c38a136d9e86daf27ac5bd8276033482b50d1548777f80073b8f988715ce9855
MD5 b5aca9f7e4a0b2196705abb847c018e5
BLAKE2b-256 628699daf28b1daa741f448808bb46c89ab47fa747d56d563373f0c521c155a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agentflowkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for agentflowkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bef4c52adacdd494a905a5a51c01838b407021c73805047051810c61cce80b2
MD5 ccad95f205d40f9cfb554368854ddff2
BLAKE2b-256 cf650249cf19dd66795c9a63b73362ed6d64ec30e8117659616fdd04efb74b64

See more details on using hashes here.

Supported by

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