Skip to content

Examples

Jason Upchurch edited this page Jan 23, 2026 · 1 revision

Examples

GENESIS includes several example applications demonstrating different patterns and capabilities.

Example Directory Structure

examples/
├── HelloWorld/           # Minimal agent + service
├── MultiAgent/           # Agent-to-agent communication
├── GraphInterface/       # Chat with visualization
├── ExampleInterface/     # Interface patterns
└── StandaloneGraphViewer/ # Topology visualization

HelloWorld Example

The simplest starting point - a basic agent and calculator service.

Running the Example

# Terminal 1: Start the service
cd examples/HelloWorld
python hello_world_service.py

# Terminal 2: Start the agent
python hello_world_agent.py

Key Files

File Description
hello_world_agent.py Simple OpenAI agent
hello_world_service.py Calculator service with add/multiply
mcp_agent.py Agent with MCP support

MultiAgent Example

Demonstrates agent-to-agent delegation with a PersonalAssistant that routes to specialist agents.

Architecture

User → PersonalAssistant → WeatherAgent → Weather API
                        → FinanceAgent → Stock API

Running

# Terminal 1: Weather Agent
python agents/weather_agent.py

# Terminal 2: Personal Assistant
python agents/personal_assistant.py

# Terminal 3: Interface
python interfaces/interactive_cli.py

Key Patterns

  1. Agent Discovery: PersonalAssistant discovers WeatherAgent automatically
  2. Agent-as-Tool: WeatherAgent appears as a tool to the LLM
  3. Delegation: "What's the weather?" routes to WeatherAgent

GraphInterface Example

Chat interface with real-time topology visualization.

Features

  • Web-based chat UI
  • Live graph showing agents, services, connections
  • Request tracing visualization

Running

python graph_interface.py
# Open http://localhost:5000 in browser

Common Patterns

Pattern 1: Simple Agent

from genesis_lib.openai_genesis_agent import OpenAIGenesisAgent

class SimpleAgent(OpenAIGenesisAgent):
    def __init__(self):
        super().__init__(
            model_name="gpt-4o",
            agent_name="SimpleAgent"
        )

async def main():
    agent = SimpleAgent()
    response = await agent.process_message("Hello!")
    print(response)
    await agent.close()

asyncio.run(main())

Pattern 2: Service with Multiple Functions

from genesis_lib.monitored_service import MonitoredService
from genesis_lib.decorators import genesis_function

class MathService(MonitoredService):
    def __init__(self):
        super().__init__("MathService", capabilities=["math"])
        self._advertise_functions()

    @genesis_function()
    async def add(self, a: float, b: float) -> Dict[str, Any]:
        """Add two numbers."""
        return {"result": a + b}

    @genesis_function()
    async def multiply(self, a: float, b: float) -> Dict[str, Any]:
        """Multiply two numbers."""
        return {"result": a * b}

    @genesis_function()
    async def factorial(self, n: int) -> Dict[str, Any]:
        """Calculate factorial of n."""
        result = 1
        for i in range(2, n + 1):
            result *= i
        return {"result": result}

asyncio.run(MathService().run())

Pattern 3: Agent with Internal Tools

from genesis_lib.openai_genesis_agent import OpenAIGenesisAgent
from genesis_lib.decorators import genesis_tool
from datetime import datetime

class ToolAgent(OpenAIGenesisAgent):
    def __init__(self):
        super().__init__(model_name="gpt-4o", agent_name="ToolAgent")

    @genesis_tool
    async def get_current_time(self) -> str:
        """Get the current date and time."""
        return datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    @genesis_tool
    async def calculate(self, expression: str) -> str:
        """Evaluate a math expression safely."""
        return str(eval(expression))  # Use safer eval in production

Pattern 4: Agent-to-Agent Communication

class OrchestratorAgent(OpenAIGenesisAgent):
    def __init__(self):
        super().__init__(
            model_name="gpt-4o",
            agent_name="Orchestrator",
            enable_agent_communication=True  # Enable agent discovery
        )

Testing Examples

Run the test suite to verify examples work:

cd tests
./run_all_tests.sh

Related Pages

Clone this wiki locally