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
构造器详情Constructor Detail
ThreadBudgetMiddleware
public ThreadBudgetMiddleware(int maxModelCallsPerThread)
初始化 ThreadBudgetMiddleware 实例。
Creates a new instance.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
maxModelCallsPerThread | int | 最大模型调用每个会话线程(类型 `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 |
|---|---|---|
agent | Agent | 智能体(类型 `Agent`)。The agent. |
ctx | RuntimeContext | 运行时上下文(类型 `RuntimeContext`)。The ctx. |
input | ReasoningInput | 输入消息(类型 `ReasoningInput`)。The input. |
next | Function<ReasoningInput, Flux<AgentEvent>> | 下一个(类型 `Function >`)。The next. |
Flux<AgentEvent>返回Flux。Returns flux.
源码Source
io/agentscope/harness/coding/middleware/ThreadBudgetMiddleware.java:50–81resetThread
public void resetThread(String threadId)
重置会话线程。
Resets the thread.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
threadId | String | 会话线程标识(类型 `String`)。The thread id. |
源码Source
io/agentscope/harness/coding/middleware/ThreadBudgetMiddleware.java:83–85