reminix.runtime.Agent¶
- class reminix.runtime.Agent[source]¶
Bases:
objectAn AI agent that can handle invoke and chat requests.
Use separate handlers for non-streaming and streaming responses: -
@agent.invoke/@agent.chatfor non-streaming -@agent.invoke_stream/@agent.chat_streamfor streamingExample:
agent = Agent(name="my-agent") @agent.invoke async def handle_invoke(input: dict, ctx: Context): return {"output": f"Processed: {input}"} @agent.invoke_stream async def handle_invoke_stream(input: dict, ctx: Context): for word in ["Hello", " ", "World"]: yield {"chunk": word} @agent.chat async def handle_chat(messages: list, ctx: Context): return {"message": {"role": "assistant", "content": "Hello!"}} @agent.chat_stream async def handle_chat_stream(messages: list, ctx: Context): for word in ["Hello", "!", " How can I help?"]: yield {"chunk": word}
Methods
__init__(name, *[, metadata])Initialize an agent with a name and optional metadata.
chat(handler)Decorator to register a non-streaming chat handler.
chat_stream(handler)Decorator to register a streaming chat handler.
handle_chat(messages[, ctx])Execute the non-streaming chat handler.
handle_chat_stream(messages[, ctx])Execute the streaming chat handler.
handle_invoke(input_data[, ctx])Execute the non-streaming invoke handler.
handle_invoke_stream(input_data[, ctx])Execute the streaming invoke handler.
invoke(handler)Decorator to register a non-streaming invoke handler.
invoke_stream(handler)Decorator to register a streaming invoke handler.
to_info()Return agent information for discovery.
Attributes
Check if non-streaming chat handler is registered.
Check if streaming chat handler is registered.
Check if non-streaming invoke handler is registered.
Check if streaming invoke handler is registered.
Get the agent's metadata.
- to_info()[source]¶
Return agent information for discovery.
- Return type:
AgentInfo- Returns:
AgentInfo dict with name, capabilities, and metadata.
- invoke(handler)[source]¶
Decorator to register a non-streaming invoke handler.
The handler receives the input dict and should return {“output”: …}.
Example:
@agent.invoke async def handle_invoke(input: dict): return {"output": f"Result: {input['query']}"}
- invoke_stream(handler)[source]¶
Decorator to register a streaming invoke handler.
The handler receives the input dict and should yield {“chunk”: “…”}.
Example:
@agent.invoke_stream async def handle_invoke_stream(input: dict): for word in ["Hello", " ", "World"]: yield {"chunk": word}
- chat(handler)[source]¶
Decorator to register a non-streaming chat handler.
The handler receives the messages list and should return {“message”: {“role”: “assistant”, “content”: “…”}}.
Example:
@agent.chat async def handle_chat(messages: list): return { "message": { "role": "assistant", "content": "Hello! How can I help?" } }
- Return type:
Callable[[list[ChatMessage]],Any]- Parameters:
handler (Callable[[list[ChatMessage]], Any])
- chat_stream(handler)[source]¶
Decorator to register a streaming chat handler.
The handler receives the messages list and should yield {“chunk”: “…”}.
Example:
@agent.chat_stream async def handle_chat_stream(messages: list): for word in ["Hello", "!", " How can I help?"]: yield {"chunk": word}
- Return type:
Callable[[list[ChatMessage]],Any]- Parameters:
handler (Callable[[list[ChatMessage]], Any])
- async handle_invoke_stream(input_data, ctx=None)[source]¶
Execute the streaming invoke handler.
- Parameters:
- Return type:
AsyncGenerator[StreamChunk,None]- Returns:
An async generator yielding StreamChunks.
- Raises:
NotImplementedError – If no streaming invoke handler is registered.
- async handle_chat(messages, ctx=None)[source]¶
Execute the non-streaming chat handler.
- Parameters:
messages (
list[ChatMessage]) – The chat messages from the request.ctx (
Context|None) – Optional request context (passed if handler accepts it).
- Return type:
ChatResponse- Returns:
A ChatResponse dict with message.
- Raises:
NotImplementedError – If no chat handler is registered.
- async handle_chat_stream(messages, ctx=None)[source]¶
Execute the streaming chat handler.
- Parameters:
messages (
list[ChatMessage]) – The chat messages from the request.ctx (
Context|None) – Optional request context (passed if handler accepts it).
- Return type:
AsyncGenerator[StreamChunk,None]- Returns:
An async generator yielding StreamChunks.
- Raises:
NotImplementedError – If no streaming chat handler is registered.