Basic Agent

A simple Python agent with invoke and chat handlers

A simple example demonstrating an agent with both invoke and chat handlers.

The Agent

from reminix.runtime import Agent, serve

# Create an agent
agent = Agent("echo")

@agent.invoke
async def handle_invoke(input_data: dict) -> dict:
    """Process invoke requests by echoing the input."""
    message = input_data.get("message", "")
    return {"output": f"You said: {message}"}

@agent.chat
async def handle_chat(messages: list) -> dict:
    """Process chat requests by echoing the last message."""
    last_message = messages[-1]["content"] if messages else ""
    return {
        "message": {
            "role": "assistant",
            "content": f"Echo: {last_message}",
        }
    }

if __name__ == "__main__":
    serve(agent, port=8080)

Running

python agent.py

Testing

# Health check
curl http://localhost:8080/health

# Agent health
curl http://localhost:8080/agent/echo/health

# Invoke
curl -X POST http://localhost:8080/agent/echo/invoke \
    -H "Content-Type: application/json" \
    -d '{"input": {"message": "Hello!"}, "stream": false}'

# Chat
curl -X POST http://localhost:8080/agent/echo/chat \
    -H "Content-Type: application/json" \
    -d '{"messages": [{"role": "user", "content": "Hello!"}], "stream": false}'

Response Examples

Invoke response:

{"output": "You said: Hello!"}

Chat response:

{"message": {"role": "assistant", "content": "Echo: Hello!"}}

Next Steps

On this page