Haive Agent Protocol - MCP for Agents
Project description
HAP - Haive Agent Protocol
"MCP for Agents" - A protocol for orchestrating multiple AI agents in complex workflows.
๐ฏ Overview
HAP (Haive Agent Protocol) enables seamless orchestration of multiple AI agents, similar to how MCP (Model Context Protocol) exposes tools and resources. It provides a standardized way to coordinate agents working together on complex multi-step problems that no single agent can solve alone.
Key Features
- ๐ Multi-Agent Orchestration - Sequential, parallel, and conditional workflows
- ๐ Protocol-Based Communication - JSON-RPC 2.0 standard for remote agents
- ๐ State Management - Context flows seamlessly between agents
- ๐ ๏ธ Tool Integration - Access individual agent tools directly
- ๐ Performance Monitoring - Track execution times and statistics
- ๐ Flexible Deployment - Local in-process or distributed network execution
๐ Quick Start
Basic Agent Workflow
from haive.hap.models.graph import HAPGraph
from haive.hap.server.runtime import HAPRuntime
from haive.agents.simple import SimpleAgent
from haive.core.engine.aug_llm import AugLLMConfig
# Create specialized agents
researcher = SimpleAgent(
name="researcher",
engine=AugLLMConfig(
temperature=0.7,
system_message="You gather comprehensive information on topics."
)
)
analyst = SimpleAgent(
name="analyst",
engine=AugLLMConfig(
temperature=0.3,
system_message="You analyze findings and identify key insights."
)
)
# Build workflow graph
graph = HAPGraph()
graph.add_agent_node("research", researcher, next_nodes=["analyze"])
graph.add_agent_node("analyze", analyst)
graph.entry_node = "research"
# Execute workflow
runtime = HAPRuntime(graph)
result = await runtime.run({"topic": "AI in Healthcare"})
print(f"Workflow path: {result.execution_path}")
print(f"Final output: {result.outputs}")
Parallel Agent Execution
# Create agents for parallel analysis
sentiment_agent = SimpleAgent(name="sentiment", engine=sentiment_config)
topic_agent = SimpleAgent(name="topics", engine=topic_config)
summary_agent = SimpleAgent(name="summary", engine=summary_config)
# Build parallel workflow
graph = HAPGraph()
graph.add_agent_node("sentiment", sentiment_agent, next_nodes=["combine"])
graph.add_agent_node("topics", topic_agent, next_nodes=["combine"])
graph.add_agent_node("summary", summary_agent, next_nodes=["combine"])
graph.add_agent_node("combine", combiner_agent)
# Multiple entry points for parallel execution
graph.entry_node = ["sentiment", "topics", "summary"]
runtime = HAPRuntime(graph)
result = await runtime.run({"text": "Customer feedback data..."})
Agent as Service
from haive.hap.servers.agent import AgentServer
# Wrap any agent as HAP server
server = AgentServer(
agent=my_agent,
expose_tools=True, # Expose individual tools
expose_state=True # Expose agent state
)
# Access agent capabilities
info = server.get_resource("agent://my_agent/info")
stats = server.get_resource("agent://my_agent/stats")
# Execute agent
result = await server.execute({
"input_data": {"query": "Process this request"},
"timeout": 30.0
})
๐ฆ Installation
# Install with poetry
poetry add haive-hap
# Or with pip
pip install haive-hap
๐๏ธ Architecture
Core Components
-
Graph Definition (
models/graph.py)HAPGraph- Define agent workflows as directed graphsHAPNode- Individual workflow nodes (agents, tools, decisions)- Support for sequential, parallel, and conditional execution
-
Runtime Engine (
server/runtime.py)HAPRuntime- Execute workflows with state management- Automatic agent loading from entrypoints
- Error handling and recovery
-
Protocol Layer (
types/protocol.py)- JSON-RPC 2.0 compliant messaging
- Comprehensive Pydantic validation
- Standard error codes and handling
-
Agent Server (
servers/agent.py)- Expose any Haive agent as HAP service
- Tool-level granularity
- Resource endpoints for state and config
๐ Real-World Use Cases
1. Research Pipeline
# Research โ Analysis โ Report Generation
graph = HAPGraph()
graph.add_agent_node("research", research_agent, next_nodes=["analyze"])
graph.add_agent_node("analyze", analysis_agent, next_nodes=["report"])
graph.add_agent_node("report", report_agent)
2. Customer Support Workflow
# Classify โ Route โ Respond โ Follow-up
graph = HAPGraph()
graph.add_agent_node("classify", classifier, next_nodes=["technical", "billing", "general"])
graph.add_agent_node("technical", tech_agent, next_nodes=["followup"])
graph.add_agent_node("billing", billing_agent, next_nodes=["followup"])
graph.add_agent_node("general", general_agent, next_nodes=["followup"])
graph.add_agent_node("followup", followup_agent)
3. Content Creation Pipeline
# Plan โ Research โ Write โ Edit โ Publish
graph = HAPGraph()
graph.add_agent_node("plan", planner, next_nodes=["research"])
graph.add_agent_node("research", researcher, next_nodes=["write"])
graph.add_agent_node("write", writer, next_nodes=["edit"])
graph.add_agent_node("edit", editor, next_nodes=["publish"])
graph.add_agent_node("publish", publisher)
๐ง Advanced Features
Dynamic Agent Loading
# Load agents from entrypoints (for distributed deployment)
graph = HAPGraph()
graph.add_entrypoint_node(
"analyzer",
"mypackage.agents:AnalyzerAgent",
config={"temperature": 0.3}
)
Conditional Routing
# Route based on agent output
def routing_function(context):
score = context.outputs.get("confidence", 0)
return "expert" if score < 0.7 else "finalize"
graph.add_decision_node(
"router",
decision_func=routing_function,
next_nodes={"expert": "expert_agent", "finalize": "final_agent"}
)
State Persistence
# Save and restore workflow state
runtime = HAPRuntime(graph, state_file="workflow_state.json")
# Resume from checkpoint
result = await runtime.resume_from_checkpoint()
๐ Performance Monitoring
# Get execution statistics
stats = runtime.get_stats()
print(f"Total executions: {stats['execution_count']}")
print(f"Average time: {stats['average_execution_time']:.2f}s")
# Per-node performance
for node, metadata in result.node_metadata.items():
print(f"{node}: {metadata['execution_time']:.2f}s")
๐งช Testing
# Run all tests (real agents, no mocks)
poetry run pytest
# Test specific components
poetry run pytest tests/test_graph_execution.py -v
poetry run pytest tests/test_agent_server.py -v
poetry run pytest tests/test_hap_workflow.py -v
# Integration tests
poetry run pytest tests/integration/ -v
๐ Documentation
Building Documentation
# Build enhanced Sphinx docs
cd docs
poetry run sphinx-build -b html source build
# View locally
python -m http.server 8003 --directory build
Documentation Features
- ๐จ Enhanced Furo theme with purple/violet styling
- ๐ก Interactive tooltips and code examples
- ๐ฑ Mobile-optimized responsive design
- ๐ Advanced search with syntax highlighting
- ๐ Hierarchical API reference organization
๐ค Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Write tests for your changes (no mocks!)
- Ensure all tests pass (
poetry run pytest) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
MIT License - see LICENSE for details.
๐ฎ Roadmap
- v0.2.0 - WebSocket transport for real-time updates
- v0.3.0 - Distributed workflow execution
- v0.4.0 - Visual workflow builder UI
- v0.5.0 - GraphQL API interface
- v1.0.0 - Production-ready with performance optimizations
๐ Acknowledgments
HAP is inspired by the Model Context Protocol (MCP) but adapted specifically for agent orchestration. Special thanks to the Haive framework team for providing the foundation for advanced agent development.
HAP - Orchestrating AI agents with elegance and power. ๐
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 haive_hap-1.0.0.tar.gz.
File metadata
- Download URL: haive_hap-1.0.0.tar.gz
- Upload date:
- Size: 36.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8a8b1ccd6a42d68fd39fe1d5adfe4ed8411540823ac3fbeffb771783740ab58
|
|
| MD5 |
2446b76a71623f8ab4fb249ed6d169a6
|
|
| BLAKE2b-256 |
82ddb10b64c8bd2c213527c1cacf267f1d87910daecc91aab3eedd2646bb6b62
|
File details
Details for the file haive_hap-1.0.0-py3-none-any.whl.
File metadata
- Download URL: haive_hap-1.0.0-py3-none-any.whl
- Upload date:
- Size: 45.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
235b1d562aa66744ff1eaf7a31576713527759c184d4c31a4eb937863b605dc3
|
|
| MD5 |
72ef4f740584876585f8bc5b49f2a212
|
|
| BLAKE2b-256 |
22010ff8489f51e6ed541d88e3e0384031499a0cc472878b424911d277c5227e
|