AS AgentScopeAPI 手册 / API Reference

ThreadBudgetMiddleware

public class ThreadBudgetMiddleware implements MiddlewareBase
源码Source io/agentscope/harness/coding/middleware/ThreadBudgetMiddleware.java:39–86

会话线程预算中间件,在智能体执行流程中提供横切扩展。位于 io.agentscope.harness.coding.middleware 包,实现 MiddlewareBase。核心成员包括 onReasoning、resetThread、ThreadBudgetMiddleware。

Middleware that enforces per-thread token and model-call budgets.

Tracks cumulative model call counts per thread (using MessageQueueMiddleware#CURRENT_THREAD_ID). When the limit is reached, raises an exception to terminate the run.

The new per-thread budget concept.

构造器摘要Constructor Summary

构造器Constructor说明Description
public ThreadBudgetMiddleware(int maxModelCallsPerThread)
初始化 `ThreadBudgetMiddleware` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public Flux<AgentEvent> onReasoning(Agent agent, RuntimeContext ctx, ReasoningInput input, Function<ReasoningInput, Flux<AgentEvent>> next)
处理推理事件。
Performs the on reasoning operation.
public void resetThread(String threadId)
重置会话线程。
Resets the thread.

构造器详情Constructor Detail

ThreadBudgetMiddleware

public ThreadBudgetMiddleware(int maxModelCallsPerThread)

初始化 ThreadBudgetMiddleware 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
maxModelCallsPerThreadint最大模型调用每个会话线程(类型 `int`)。The max model calls per thread.
源码Source io/agentscope/harness/coding/middleware/ThreadBudgetMiddleware.java:46–48

方法详情Method Detail

onReasoning

public Flux<AgentEvent> onReasoning(Agent agent, RuntimeContext ctx, ReasoningInput input, Function<ReasoningInput, Flux<AgentEvent>> next)

处理推理事件。

Performs the on reasoning operation.

参数Parameters
名称Name类型Type说明Description
agentAgent智能体(类型 `Agent`)。The agent.
ctxRuntimeContext运行时上下文(类型 `RuntimeContext`)。The ctx.
inputReasoningInput输入消息(类型 `ReasoningInput`)。The input.
nextFunction<ReasoningInput, Flux<AgentEvent>>下一个(类型 `Function >`)。The next.
返回Returns Flux<AgentEvent>
返回Flux。Returns flux.
源码Source io/agentscope/harness/coding/middleware/ThreadBudgetMiddleware.java:50–81

resetThread

public void resetThread(String threadId)

重置会话线程。

Resets the thread.

参数Parameters
名称Name类型Type说明Description
threadIdString会话线程标识(类型 `String`)。The thread id.
源码Source io/agentscope/harness/coding/middleware/ThreadBudgetMiddleware.java:83–85

继承成员Inherited Members

继承自Methods inherited from MiddlewareBase
基于官方固定版本源码静态生成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.