Class AguiAgentAdapter

java.lang.Object
io.agentscope.core.agui.adapter.AguiAgentAdapter

public class AguiAgentAdapter extends Object
Adapter that bridges AgentScope agents to the AG-UI protocol.

This adapter converts AG-UI protocol inputs to AgentScope messages, invokes the agent, and converts the streaming events back to AG-UI events.

Event Mapping:

  • AgentScope REASONING/SUMMARY events → AG-UI TEXT_MESSAGE_* events (for TextBlock)
  • AgentScope REASONING/SUMMARY events → AG-UI REASONING_* events (for ThinkingBlock, when enabled)
  • AgentScope TOOL_RESULT events → AG-UI TOOL_CALL_END events
  • ToolUseBlock content → AG-UI TOOL_CALL_START events

Reasoning Support:

  • ThinkingBlock content is converted to REASONING_* events according to AG-UI Reasoning draft
  • Reasoning output is disabled by default (enableReasoning=false) for backward compatibility
  • Set enableReasoning=true in AguiAdapterConfig to enable reasoning events
  • Field Details

  • Constructor Details

    • AguiAgentAdapter

      public AguiAgentAdapter(io.agentscope.core.agent.Agent agent, AguiAdapterConfig config)
      Creates a new AguiAgentAdapter.
      Parameters:
      agent - The agent to adapt
      config - The adapter configuration
  • Method Details

    • run

      public reactor.core.publisher.Flux<AguiEvent> run(RunAgentInput input)
      Run the agent with AG-UI protocol input.

      This method converts the input messages, invokes the agent's streaming API, and emits AG-UI protocol events.

      Parameters:
      input - The AG-UI run input
      Returns:
      A Flux of AG-UI events
    • run

      public reactor.core.publisher.Flux<AguiEvent> run(RunAgentInput input, io.agentscope.core.agent.RuntimeContext runtimeContext)
      Run the agent with AG-UI protocol input and caller-provided runtime context.

      The provided context is copied and enriched with AG-UI runtime metadata. AG-UI metadata and the session id are always derived from input so callers can add custom values without losing the protocol defaults.

      Parameters:
      input - The AG-UI run input
      runtimeContext - Optional caller-provided runtime context
      Returns:
      A Flux of AG-UI events
    • buildRuntimeContext

      protected io.agentscope.core.agent.RuntimeContext buildRuntimeContext(RunAgentInput input, io.agentscope.core.agent.RuntimeContext runtimeContext)
      Build the runtime context used for the agent invocation.

      The caller-provided context is copied first, then AG-UI protocol metadata is applied so that required request values and session isolation are always preserved. A per-call tool request config is built from the frontend tools and carried via RuntimeContext.getToolRequestConfig() so the shared toolkit is never mutated and concurrent runs on the same agent are isolated.

      Parameters:
      input - The AG-UI run input
      runtimeContext - Optional caller-provided runtime context
      Returns:
      The effective runtime context for this run