𝗔𝗜 𝗔𝗴𝗲𝗻𝘁 𝗦𝗰𝗼𝗽𝗲𝘀 𝗔𝗻𝗱 𝗧𝗼𝗼𝗹 𝗟𝗶𝗳𝗲𝗰𝘆𝗰𝗹𝗲𝘀
Building AI agents is hard because you cannot easily control them. You need to limit costs. You need to stop runaway loops. You need to see exactly what happened when a run fails.
I built a new way to handle this. It uses an agent primitive called runAgent with AgentScope. It includes budgets, replayable events, and structured cancellation.
Here is how it works:
- Tool functions are plain async functions. No complex schemas are required.
- Budgets are checked before a tool returns. If you hit a limit, the system cancels the entire run.
- Retries and timeouts happen at the tool level.
- Cancellation propagates. If a user stops the agent, the system aborts the active fetch or database query immediately.
- You get a replayable log. Every event is typed and ordered.
You can set three types of limits:
- CostBudget: Limits total USD spent.
- OpenAITokens: Limits total tokens used.
- AgentToolCalls: Limits total tool calls to stop runaway loops.
This approach is different from other frameworks. Most frameworks use heavy JSON schemas or loose typing. They often lack first-class budget primitives. They do not have a unified way to cancel everything at once.
With this system, your agent shares the same lifecycle as your application. If the parent process stops, the agent stops. There is no second runtime to manage.
You can use the event log to:
- Build dashboards for failure heatmaps.
- Replay a run in a test environment.
- Audit exact charges by looking at tool success events.
- Compare two different runs to see where they diverged.
This makes AI agents predictable and safe for production.
Source: https://github.com/WorkRuntime/workit
Optional learning community: https://t.me/GyaanSetuAi