microagents-events 0.1.0

Typed-, JSONRPC-compatible events definitions for the microagents framework
Documentation

microagents-events

Event types and JSON-RPC serialization for the microagents framework.

Overview

This crate defines the core event types that flow through an agent session: initialization, user prompts, streaming deltas, tool calls, skill loading and assistant responses. Each event can be converted to and from a JSON-RPC 2.0 notification for transport over a wire or between processes.

Event Types

Event Method Description
SessionInitEvent session.init A new or resumed session starts
SessionStopEvent session.stop A session ends with success or error
UserPromptSubmitEvent user.prompt.submit The user sends a prompt
StreamDeltaEvent stream.delta A chunk of streaming response (text or thinking)
ToolCallEvent tool.call The model requests a tool invocation
ToolResultEvent tool.result A tool returns its output
SkillLoadEvent skill.load A skill is loaded into the session
AssistantResponseEvent assistant.response The model produces a complete response

Usage

use microagents_events::*;
use chrono::Utc;

let event = SessionInitEvent {
    session_id: "sess-1".into(),
    model: "gpt-4".into(),
    provider: "openai".into(),
    system: "You are a helpful assistant.".into(),
    init_type: SessionInitType::Start,
    timestamp: Utc::now(),
};

let rpc = event.to_jsonrpc();
// rpc.method == "session.init"
// rpc.params["session_id"] == "sess-1"

Round-trip

use chrono::Utc;

let rpc = JsonRpcNotification::builder()
    .method("user.prompt.submit".into())
    .add_param("session_id".into(), "s1".into())
    .add_param("turn_id".into(), "t1".into())
    .add_param("prompt".into(), "Hello!".into())
    .add_param("timestamp", serde_json::to_value(Utc::now()).unwrap());

let any = AgentEventAny::try_from(rpc)?;

License

MIT