Opfer
Opfer is a Python framework for building AI agent applications with workflow orchestration, tool integration, and observability.
Features
- Agent System: Define AI agents with custom tools and instructions
- Workflow Orchestration: Build complex workflows with async task composition
- Multi-Provider Support: Integrate with various AI model providers (Google GenAI, etc.)
- Observability: Built-in tracing with OpenTelemetry support
- Artifact Management: Handle files and binary data with flexible storage backends
- Agent Composition: Use agents as tools in other agents
Requirements
- Python 3.13+
Installation
pip install opfer
Optional Dependencies
For Google GenAI support:
pip install opfer[google_genai]
For OpenTelemetry tracing:
pip install opfer[opentelemetry]
Quick Start
Basic Agent
from opfer.core import Agent
from opfer.types import ModelConfig
async def add(a: float, b: float) -> float:
return a + b
async def multiply(a: float, b: float) -> float:
return a * b
math_agent = Agent(
id="math_agent",
display_name="Math Agent",
instruction="You are a math agent.",
tools=[add, multiply],
model=ModelConfig(
provider="google",
name="gemini-2.5-flash-lite",
),
)
Agent Composition
Agents can use other agents as tools:
assistant = Agent(
id="assistant",
display_name="Super Helpful Assistant",
instruction="You are a helpful assistant.",
tools=[
math_agent.as_tool(
description="Use this tool to answer math questions.",
),
],
model=ModelConfig(
provider="google",
name="gemini-2.5-flash-lite",
),
)
Workflow
Build complex workflows with async task composition:
from opfer.workflow import Workflow
async def load_data() -> str:
# Load and process data
return "processed_data"
async def analyze(data: str) -> str:
# Analyze data
return f"Analysis of {data}"
async def my_workflow():
async with Workflow() as w:
data = w.run(load_data())
result = data.then(lambda d: analyze(d))
return await result
Artifact Management
Handle files and binary data with artifact storage:
import io
from PIL import Image
from opfer.artifacts import File, upload_artifact, download_artifact
async def process_image():
# Load image
image = Image.open("image.png")
buf = io.BytesIO()
image.save(buf, format="PNG")
# Upload as artifact
file = File(
name="image.png",
data=buf.getvalue(),
mime_type="image/png",
)
url = await upload_artifact(file)
# Download artifact
downloaded = await download_artifact(url)
return downloaded
Configuration
Set up storage backends and model providers:
from contextlib import asynccontextmanager
from opfer.provider import DefaultModelProviderRegistry, set_model_provider_registry
from opfer.artifacts import set_artifact_storage
from opfer.blob import set_blob_storage
set_model_provider_registry(DefaultModelProviderRegistry())
set_artifact_storage(InMemoryArtifactStorage())
set_blob_storage(InMemoryBlobStorage())
Observability
Enable tracing:
from opfer.tracing import trace, tracer, get_current_span
# Add custom events to spans
async def monitored_function(a: float, b: float) -> float:
span = get_current_span()
if span:
span.add_event("Function called", {"a": a, "b": b})
return a * b
# Trace entire workflows
async def main():
with trace():
result = await my_workflow()
Complete Example
See examples/basic/example.py for a complete working example that demonstrates:
- Creating agents with custom tools
- Agent composition (assistant using math agent)
- Workflow orchestration with async tasks
- Image processing with artifact storage
- OpenTelemetry integration for tracing
- Google GenAI provider registration
To run the example:
python examples/basic/example.py
Architecture
Core Components
- Agent: AI agents with custom tools and instructions
- Workflow: Async task orchestration with composable operations
- Provider: Abstraction for AI model providers
- Artifacts: File and data management with pluggable storage
- Blob: Binary data storage with content-addressable URLs
- Tracing: Observability with span-based tracing
Storage Backends
Opfer provides flexible storage backends for artifacts and blobs:
- In-memory storage (for development/testing)
- Custom storage implementations (implement the storage interface)
Model Providers
Currently supported:
- Google GenAI (via
google-genaipackage)
Metadata
Release files for opfer 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opfer-0.1.0.tar.gz | 56.1 kB | Without provenance | Details for opfer-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opfer-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for opfer-0.1.0-py3-none-any.whl |
Total release size: 86.9 kB
Release files / opfer-0.1.0.tar.gz
| Download URL | opfer-0.1.0.tar.gz |
|---|---|
| Size | 56.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d11ceb471758efa4f0e647849b00ed24bd3021d7338599d1320b54588f132bb3
|
|
BLAKE2b-256 checksum How to use checksums |
a5d5059a7fb8175e80cc92d6f58105df2cd37f2b9c156ca7beb72b9effa7ca92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|
Release files / opfer-0.1.0-py3-none-any.whl
| Download URL | opfer-0.1.0-py3-none-any.whl |
|---|---|
| Size | 30.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c8533e1a6e4a46c29fd620d1860105897b7a67bdf327a6d88dd92bc99139cca1
|
|
BLAKE2b-256 checksum How to use checksums |
dbb35160fc3e25bab6c445e3e8d7eb1f6015217e7fab826d8c03320ce53ac886
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|
Security for opfer 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.