Skip to main content

A lightweight library for creating and managing AI agent circuits

Project description

Pions

A lightweight, modular agent library for building AI agent systems with circuit-based workflows.

Overview

Pions provides a simple yet powerful architecture for building agent-based systems using a circuit-based approach. It includes:

  • Protocol definitions for agents and tools
  • Base classes for extending agent and tool functionality
  • A controller agent for orchestrating complex workflows
  • Circuit components for visualizing and composing agent workflows
  • Example implementations to get started quickly

Core Components

Circuits

Circuits are the fundamental building blocks in Pions. They allow for the composition of agents and tools into complex workflows.

from pions.circuits import CircuitBuilder, CircuitVisualizer

# Create a simple weather information circuit
weather_circuit = CircuitBuilder.series(
    name="Weather Information Circuit",
    components=[
        FunctionComponent(entity_extractor),
        ToolComponent(WeatherTool()),
        FunctionComponent(result_formatter)
    ]
)

# Visualize the circuit
print(CircuitVisualizer.visualize_circuit(weather_circuit, "text"))
print(CircuitVisualizer.visualize_circuit(weather_circuit, "mermaid"))

# Process a query through the circuit
result = await weather_circuit.process({"query": "What's the weather in San Francisco?"})

Agents

Agents are the primary actors in the system. They implement the AgentProtocol and can process queries to produce results.

from pions import Agent

class MyCustomAgent(Agent):
    def __init__(self):
        super().__init__(name="my_custom_agent")
    
    async def process(self, query: str, **kwargs):
        # Implement your agent's logic here
        return {"result": f"Processed: {query}"}

Tools

Tools are utilities that agents can use to perform specific tasks. They implement the ToolProtocol.

from pions import BaseTool

class MyCustomTool(BaseTool):
    def __init__(self):
        super().__init__(name="my_custom_tool")
    
    async def execute(self, *args, **kwargs):
        # Implement your tool's logic here
        return {"result": "Tool executed"}

Controller

The ControllerAgent orchestrates multiple agents and tools, facilitating complex workflows. For more advanced workflows, consider using the circuit-based approach.

from pions import ControllerAgent

# Create controller
controller = ControllerAgent(name="my_controller")

# Register agents and tools
controller.register_agent(my_agent)
controller.register_tool(my_tool)

# Process queries
result = await controller.process("My query", agent_name="my_agent")

# Execute tools directly
tool_result = await controller.execute_tool("my_tool", arg1, arg2)

# Run pipelines
pipeline_result = await controller.run_pipeline(
    "My pipeline query",
    ["agent1", "agent2", "tool1"]
)

Examples

The library includes example implementations in the examples.py and circuit_examples.py modules:

# Traditional agent example
from pions.examples import ResearchAgent, ContentAnalysisAgent

# Create and use example agents
research_agent = ResearchAgent()
result = await research_agent.process("How does AI work?")

# Circuit-based example
from pions.circuit_examples import create_weather_circuit

# Create a weather information circuit
weather_circuit = create_weather_circuit()

# Process a query through the circuit
result = await weather_circuit.process({"query": "What's the weather in San Francisco?"})
print(result.get("formatted_result"))

Installation

pip install pions

Or from source:

git clone https://github.com/janhq/asimov.git
cd asimov
pip install -e .

Dependencies

Pions requires:

  • Python 3.8+
  • bhumi (for LLM inference)
  • numpy (for certain features)
  • typing-extensions

Using with Bhumi

Pions integrates seamlessly with Bhumi for LLM inference:

from bhumi.base_client import BaseLLMClient, LLMConfig
from pions import Agent

class LLMAgent(Agent):
    def __init__(self, name: str, llm_config: dict):
        super().__init__(name=name)
        self.llm_client = BaseLLMClient(LLMConfig(**llm_config))
        
    async def process(self, query: str, **kwargs):
        response = await self.llm_client.generate(query)
        return {"result": response}

# Usage
llm_config = {
    "api_key": "your_api_key",
    "model": "gemini/gemini-1.5-flash-latest",
    "debug": False
}

agent = LLMAgent("my_llm_agent", llm_config)
result = await agent.process("Tell me about quantum computing")

License

MIT License

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

quarkflow-0.1.0.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

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

quarkflow-0.1.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: quarkflow-0.1.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for quarkflow-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d686e0cc6cb8bb21c5ad51b55b2ad0389eade6639a3f64097b518d54e48e9e53
MD5 6cc20ad4f10948aa0677cf5f30083bb1
BLAKE2b-256 78ed79f0768049c72d8907b2f27b07e1706581115bee53debe59cf45e9f2b5ba

See more details on using hashes here.

File details

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

File metadata

  • Download URL: quarkflow-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for quarkflow-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fecd92d017c7edc8256a9f83ca4fa970d3e7b03872bdbcbc13b2c3bc94147a88
MD5 46d6ec3159cb86fb8b8d548b75cbc134
BLAKE2b-256 c012170613c85bedbfdbfe86c78c992ff2470cb08f15e3f11ab271d50c6da549

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