
Build Self-Improving AI Agents with Temporal and Oodle
Can you spot the difference between these two support chat experiences?
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
Can you spot the difference between these two support chat experiences?
While the support bot did the exact same thing in both cases, in the left side chat, it took twice the amount of time to respond to the user. In the crafted example above, 2s v/s 4s may not be that big a difference, but in reality, it is common to see a number of failure patterns with agentic applications:
One way to tackle these failures is a reactive mode - let your users report failure, then analyze agent traces, find why failure happened, fix and deploy it. Wouldn't it be better if your AI agents kept improving without customer needing to report bugs and any of the manual work associated? That will lead to self-improving agents.
We will use the above primitives from each platform:
Let's put together these constructs to build a self-improving loop.
The whole agent is that one loop, with ... standing in for timeouts and retry policies:
@workflow.defn(name="SupportAgentWorkflow") class SupportAgentWorkflow: @workflow.run async def run(self, ticket: dict) -> dict:
One activity call, so the whole run uses a single prompt version.
resolved = await workflow.execute_activity(resolve_prompt, PROMPT_NAME, ...) history = [user_text(ticket["text"])]
for turn in range(MAX_TURNS): step = await workflow.execute_activity(agent_turn, { "system": resolved["prompt"], "tools": resolved["tools"], "history": history, "prompt_version": resolved["version"], }, ...) history.append(step["model_content"])
Nothing left to call: this turn is the reply.
if not step["tool_calls"]: return reply_for(ticket, step, resolved["version"])
for call in step["tool_calls"]: result = await workflow.execute_activity(agent_tool, call, ...)
Errors go back to the model as tool output, not as exceptions,
so it gets a chance to correct its own arguments.
history.append(tool_response(call["name"], result))
The runnable version, with the tool-error counting and the exhausted-turns path, is SupportAgentWorkflow in worker.py.
Here is one run of this workflow in the Temporal UI:
Temporal shows multiple agent_tool invocation being made leading to more agent turns. Oodle completes the full picture by showing what those tool calls are:
We can see that there are few failures in the tool calls which was being retried by Temporal workflow. Oodle goes a step further to classify these tool call failures as a Signal classifying them as invalid_argument :
We will use these signals to build a self-improving loop next.
Here is one run of the prompt improver workflow in the Temporal UI.
Here, Oodle provided insights are used to draft an updated prompt, which is evaluated against a dataset of prior support tickets, and then post a human approval, promoted as a live version. Temporal workflow waits for human approval before executing the last activity to promote the candidate to production.
To setup the experiment evaluation, I used experiment webhooks in Oodle so that I can run the support agent over test dataset. The interesting part here is to be able to evaluate the agent loop, it is needed to invoke the agent. So, here the evaluation is not simply over a single LLM call, but rather over the entire agent loop. I added an experiment webhook in Oodle so that Oodle can invoke my support agent for each item in the dataset.
Now that I have a way for Oodle to invoke my support agent, I need a way to evaluate agent trajectories. Remember, earlier we had noticed that the support agent is making few tool calls with invalid arguments leading to tool errors. So, the evaluator I want to add is to measure whether any tool errors are happening in the agent runs.
And, what's better, I don't need LLM-as-a-judge to detect this, I added a code eval on Oodle to check this, thus, not burning any LLM tokens for this evaluation.
Once an experiment run is complete, Oodle shows results of above code eval for each item in the dataset. As we can see below, with the candidate prompt, support agent answered all items in the dataset without any tool call failures, hence, the candidate prompt is good to be promoted to production .
The above recipe highlights an approach for building self-improving loops for your AI agents. To build such a loop for your production AI agents, here are the key parts you would need to think about:
Using all of the constructs above, you can build a self-improving loop for your AI agents. You can feed insights and eval scores into a Temporal workflow and use LLMs to analyze this feedback, make improvements to the agent definition, and improve prompts and tools. This workflow can run periodically or can be driven by webhooks with appropriate human-in-the-loop approval workflows.
The example agent and improvement loop used above are available at temporal-demo/self-improving-loop.
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。