A multi-agent framework for building conversational AI systems
Project description
Graphent
A multi-agent framework for building conversational AI systems with LangChain.
Features
- 🤖 Agent Builder Pattern - Fluent API for constructing agents
- 🔗 Multi-Agent Delegation - Agents can delegate tasks to sub-agents
- 🛠️ Tool Integration - Easy integration with LangChain tools
- 🎣 Event Hooks - Comprehensive hook system for monitoring agent activity
- 📝 Conversation Context - Manage multi-turn conversations easily
- ⚡ Async Support - Full async/await support for all operations
- 🔄 Streaming - Stream responses in real-time
Installation
pip install graphent
Quick Start
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage
from lib import AgentBuilder, Context
# Create a model
model = ChatOpenAI(model="gpt-4")
# Build an agent
agent = (AgentBuilder()
.with_name("Assistant")
.with_model(model)
.with_system_prompt("You are a helpful assistant.")
.with_description("A general-purpose assistant")
.build())
# Create a conversation context and invoke
context = Context().add_message(HumanMessage(content="Hello!"))
result = agent.invoke(context)
print(result.get_messages()[-1].content)
Multi-Agent Example
from lib import AgentBuilder, Context
from lib.tools import get_coords, get_weather
# Create a specialized weather agent
weather_agent = (AgentBuilder()
.with_name("Weather Agent")
.with_model(model)
.with_system_prompt("You answer weather questions.")
.with_description("Gets weather information for locations")
.add_tool(get_coords)
.add_tool(get_weather)
.build())
# Create a main agent that can delegate to the weather agent
main_agent = (AgentBuilder()
.with_name("Main Agent")
.with_model(model)
.with_system_prompt("You are a helpful assistant.")
.with_description("Main orchestrator agent")
.add_agent(weather_agent)
.build())
# The main agent will automatically delegate weather queries
context = Context().add_message(HumanMessage(content="What's the weather in Berlin?"))
result = main_agent.invoke(context)
Event Hooks
Monitor agent activity with hooks:
from lib import AgentBuilder, on_tool_call, after_tool_call, ToolCallEvent, ToolResultEvent
class MyHooks:
@on_tool_call
def log_tool_call(self, event: ToolCallEvent):
print(f"Calling tool: {event.tool_name}")
@after_tool_call
def log_tool_result(self, event: ToolResultEvent):
print(f"Tool {event.tool_name} returned: {event.result}")
agent = (AgentBuilder()
.with_name("Agent")
.with_model(model)
.with_system_prompt("You are helpful.")
.with_description("An agent with hooks")
.add_hooks_from_object(MyHooks())
.build())
Async Support
import asyncio
from lib import AgentBuilder, Context
async def main():
context = Context().add_message(HumanMessage(content="Hello!"))
result = await agent.ainvoke(context)
print(result.get_messages()[-1].content)
asyncio.run(main())
Streaming
from lib import AgentBuilder, Context
context = Context().add_message(HumanMessage(content="Tell me a story"))
for chunk in agent.stream(context):
print(chunk, end="", flush=True)
Configuration
Configure via environment variables:
export GRAPHENT_LOG_LEVEL=25
export GRAPHENT_TRUNCATE_LIMIT=250
export GRAPHENT_MAX_ITERATIONS=10
export GRAPHENT_DEBUG=false
Or programmatically:
from lib import GraphentConfig, set_config
config = GraphentConfig(
log_level=20,
truncate_limit=500,
max_iterations=15,
debug=True
)
set_config(config)
API Reference
Core Classes
Agent- The main agent class that processes conversationsAgentBuilder- Fluent builder for constructing agentsContext- Container for conversation messages
Hooks
@on_tool_call- Before a tool is called@after_tool_call- After a tool returns@on_response- When the model generates a response@before_model_call- Before invoking the model@after_model_call- After the model returns@on_delegation- When delegating to a sub-agent
Exceptions
GraphentError- Base exception for all Graphent errorsAgentConfigurationError- Invalid agent configurationToolExecutionError- Tool execution failedDelegationError- Agent delegation failedMaxIterationsExceededError- Too many iterations
Development
# Clone the repository
git clone https://github.com/didalla/graphent.git
cd graphent
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphent-0.1.5.tar.gz.
File metadata
- Download URL: graphent-0.1.5.tar.gz
- Upload date:
- Size: 59.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6038b375569108413c97080a55d76159ad73f4059175d85010afc0cdd534cdf
|
|
| MD5 |
2b700584a10408b826685149c60279cc
|
|
| BLAKE2b-256 |
df11c9763adbef1957958a2543007d3ec2c535b689fb676690fa39f0ffe70087
|
Provenance
The following attestation bundles were made for graphent-0.1.5.tar.gz:
Publisher:
publish.yml on didalla/graphent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphent-0.1.5.tar.gz -
Subject digest:
b6038b375569108413c97080a55d76159ad73f4059175d85010afc0cdd534cdf - Sigstore transparency entry: 757505508
- Sigstore integration time:
-
Permalink:
didalla/graphent@631dae8f40d7cac667d28bfb1067f6e7b5b23fde -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/didalla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@631dae8f40d7cac667d28bfb1067f6e7b5b23fde -
Trigger Event:
push
-
Statement type:
File details
Details for the file graphent-0.1.5-py3-none-any.whl.
File metadata
- Download URL: graphent-0.1.5-py3-none-any.whl
- Upload date:
- Size: 43.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46bd91c9daae98c04bfa76ca9cbcc206869eb745808264c095f8a524d1291ddc
|
|
| MD5 |
443e19f61d15de396fae0acca770fffc
|
|
| BLAKE2b-256 |
5765eb518b90ff32a6f03266d229e3c5f92ae711d2eca14e3ad8fc84b85ee70a
|
Provenance
The following attestation bundles were made for graphent-0.1.5-py3-none-any.whl:
Publisher:
publish.yml on didalla/graphent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphent-0.1.5-py3-none-any.whl -
Subject digest:
46bd91c9daae98c04bfa76ca9cbcc206869eb745808264c095f8a524d1291ddc - Sigstore transparency entry: 757505511
- Sigstore integration time:
-
Permalink:
didalla/graphent@631dae8f40d7cac667d28bfb1067f6e7b5b23fde -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/didalla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@631dae8f40d7cac667d28bfb1067f6e7b5b23fde -
Trigger Event:
push
-
Statement type: