AS AgentScopeAPI 手册 / API Reference

AguiAgentAdapter

public class AguiAgentAdapter
源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:80–771

AGUI 智能体适配器,在智能体、模型与前端之间传递结构化消息和事件。位于 io.agentscope.core.agui.adapter 包。核心成员包括 run、buildRuntimeContext、AguiAgentAdapter、RUNTIME_CONTEXT_THREAD_ID_KEY、RUNTIME_CONTEXT_RUN_ID_KEY、RUNTIME_CONTEXT_MESSAGES_KEY。

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 Summary

字段Field类型Type说明Description
RUNTIME_CONTEXT_THREAD_ID_KEY
staticfinal
String
运行时上下文会话线程标识键字段。
The RUNTIME CONTEXT THREAD ID KEY field.
RUNTIME_CONTEXT_RUN_ID_KEY
staticfinal
String
运行时上下文运行标识键字段。
The RUNTIME CONTEXT RUN ID KEY field.
RUNTIME_CONTEXT_MESSAGES_KEY
staticfinal
String
运行时上下文消息键字段。
The RUNTIME CONTEXT MESSAGES KEY field.
RUNTIME_CONTEXT_TOOLS_KEY
staticfinal
String
运行时上下文工具键字段。
The RUNTIME CONTEXT TOOLS KEY field.
RUNTIME_CONTEXT_CONTEXT_KEY
staticfinal
String
运行时上下文上下文键字段。
The RUNTIME CONTEXT CONTEXT KEY field.
RUNTIME_CONTEXT_STATE_KEY
staticfinal
String
运行时上下文状态键字段。
The RUNTIME CONTEXT STATE KEY field.
RUNTIME_CONTEXT_FORWARDED_PROPS_KEY
staticfinal
String
运行时上下文 FORWARDED PROPS 键字段。
The RUNTIME CONTEXT FORWARDED PROPS KEY field.
RUNTIME_CONTEXT_RESUME_KEY
staticfinal
String
运行时上下文恢复键字段。
The RUNTIME CONTEXT RESUME KEY field.
RUNTIME_CONTEXT_RESUME_INTERRUPTS_KEY
staticfinal
String
运行时上下文恢复 INTERRUPTS 键字段。
The RUNTIME CONTEXT RESUME INTERRUPTS KEY field.

构造器摘要Constructor Summary

构造器Constructor说明Description
public AguiAgentAdapter(Agent agent, AguiAdapterConfig config)
创建新的AguiAgentAdapter。
Creates a new AguiAgentAdapter.

方法摘要Method Summary

方法Method说明Description
public Flux<AguiEvent> run(RunAgentInput input)
设置运行。
Run the agent with AG-UI protocol input.
public Flux<AguiEvent> run(RunAgentInput input, RuntimeContext runtimeContext)
执行运行相关操作。
Run the agent with AG-UI protocol input and caller-provided runtime context.
protected RuntimeContext buildRuntimeContext(RunAgentInput input, RuntimeContext runtimeContext)
构建运行时上下文。
Build the runtime context used for the agent invocation.

字段详情Field Detail

RUNTIME_CONTEXT_THREAD_ID_KEY

public static final String RUNTIME_CONTEXT_THREAD_ID_KEY
staticfinal

运行时上下文会话线程标识键字段。声明为 public static final String RUNTIME_CONTEXT_THREAD_ID_KEY。

The RUNTIME CONTEXT THREAD ID KEY field.

源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:82

RUNTIME_CONTEXT_RUN_ID_KEY

public static final String RUNTIME_CONTEXT_RUN_ID_KEY
staticfinal

运行时上下文运行标识键字段。声明为 public static final String RUNTIME_CONTEXT_RUN_ID_KEY。

The RUNTIME CONTEXT RUN ID KEY field.

源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:83

RUNTIME_CONTEXT_MESSAGES_KEY

public static final String RUNTIME_CONTEXT_MESSAGES_KEY
staticfinal

运行时上下文消息键字段。声明为 public static final String RUNTIME_CONTEXT_MESSAGES_KEY。

The RUNTIME CONTEXT MESSAGES KEY field.

源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:84

RUNTIME_CONTEXT_TOOLS_KEY

public static final String RUNTIME_CONTEXT_TOOLS_KEY
staticfinal

运行时上下文工具键字段。声明为 public static final String RUNTIME_CONTEXT_TOOLS_KEY。

The RUNTIME CONTEXT TOOLS KEY field.

源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:85

RUNTIME_CONTEXT_CONTEXT_KEY

public static final String RUNTIME_CONTEXT_CONTEXT_KEY
staticfinal

运行时上下文上下文键字段。声明为 public static final String RUNTIME_CONTEXT_CONTEXT_KEY。

The RUNTIME CONTEXT CONTEXT KEY field.

源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:86

RUNTIME_CONTEXT_STATE_KEY

public static final String RUNTIME_CONTEXT_STATE_KEY
staticfinal

运行时上下文状态键字段。声明为 public static final String RUNTIME_CONTEXT_STATE_KEY。

The RUNTIME CONTEXT STATE KEY field.

源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:87

RUNTIME_CONTEXT_FORWARDED_PROPS_KEY

public static final String RUNTIME_CONTEXT_FORWARDED_PROPS_KEY
staticfinal

运行时上下文 FORWARDED PROPS 键字段。声明为 public static final String RUNTIME_CONTEXT_FORWARDED_PROPS_KEY。

The RUNTIME CONTEXT FORWARDED PROPS KEY field.

源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:88

RUNTIME_CONTEXT_RESUME_KEY

public static final String RUNTIME_CONTEXT_RESUME_KEY
staticfinal

运行时上下文恢复键字段。声明为 public static final String RUNTIME_CONTEXT_RESUME_KEY。

The RUNTIME CONTEXT RESUME KEY field.

源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:89

RUNTIME_CONTEXT_RESUME_INTERRUPTS_KEY

public static final String RUNTIME_CONTEXT_RESUME_INTERRUPTS_KEY
staticfinal

运行时上下文恢复 INTERRUPTS 键字段。声明为 public static final String RUNTIME_CONTEXT_RESUME_INTERRUPTS_KEY。

The RUNTIME CONTEXT RESUME INTERRUPTS KEY field.

源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:90

构造器详情Constructor Detail

AguiAgentAdapter

public AguiAgentAdapter(Agent agent, AguiAdapterConfig config)

创建新的AguiAgentAdapter。

Creates a new AguiAgentAdapter.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。The agent to adapt
configAguiAdapterConfig适配器配置。The adapter configuration
源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:104–114

方法详情Method Detail

run

public Flux<AguiEvent> run(RunAgentInput input)

设置运行。

Run the agent with AG-UI protocol input.

参数Parameters
名称Name类型Type说明Description
inputRunAgentInputAG-UI 运行输入。The AG-UI run input
返回Returns Flux<AguiEvent>
返回Flux。A Flux of AG-UI events
源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:125–127

run

public Flux<AguiEvent> run(RunAgentInput input, RuntimeContext runtimeContext)

执行运行相关操作。

Run the agent with AG-UI protocol input and caller-provided runtime context.

参数Parameters
名称Name类型Type说明Description
inputRunAgentInputAG-UI 运行输入。The AG-UI run input
runtimeContextRuntimeContext运行时上下文(类型 `RuntimeContext`)。Optional caller-provided runtime context
返回Returns Flux<AguiEvent>
返回Flux。A Flux of AG-UI events
源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:140–189

buildRuntimeContext

protected RuntimeContext buildRuntimeContext(RunAgentInput input, RuntimeContext runtimeContext)

构建运行时上下文。

Build the runtime context used for the agent invocation.

参数Parameters
名称Name类型Type说明Description
inputRunAgentInputAG-UI 运行输入。The AG-UI run input
runtimeContextRuntimeContext运行时上下文(类型 `RuntimeContext`)。Optional caller-provided runtime context
返回Returns RuntimeContext
返回RuntimeContext。The effective runtime context for this run
源码Source io/agentscope/core/agui/adapter/AguiAgentAdapter.java:291–307
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.