feat: task cancellation (wip)

This commit is contained in:
Shivering Ocelot committed 2026-05-30 17:51:49 -05:00
1 parent 25b5fbd22a
commit 77addb889d
10 files changed
+319 -60

No files matched your search

+10 -19
View File
@@ -2,10 +2,8 @@ import inference
from agent import Agent, AgentField
CLASS_DESCRIPTION = """
Expert AI in any field, powered by Llama 3 70b.
Expert AI with customizable system prompt.
Will get guidelines, documents, and other advanced features in the future.
Available models are: [llama/qwen]-[big/small] (replicate), ollama:MODEL_NAME
""".strip()
class ExpertAgent(Agent):
@@ -22,7 +20,6 @@ class ExpertAgent(Agent):
Agent.__init__(self, app, data)
async def run(self, run):
inp = run.input or {}
opts = {}
if self.config.get("temperature") is not None:
@@ -30,26 +27,20 @@ class ExpertAgent(Agent):
if self.config.get("repetition_penalty") is not None:
opts["repetition_penalty"] = self.config["repetition_penalty"]
# 1. Build message list based on input mode
if "messages" in inp:
messages = inp["messages"]
else:
instruction = inp.get("instruction")
input_text = inp.get("input")
messages = inference.build_messages(
system_prompt=self.config.get("system_prompt", ""),
instruction=instruction,
input=input_text,
messages=inp.get("messages"),
)
# 1. Build message list based on input
messages = inference.build_messages(
system_prompt=self.config.get("system_prompt", ""),
instruction=run.input.get("instruction"),
input=run.input.get("input"),
messages=run.input.get("messages"),
)
# 2. Call inference, passing the run so it feeds run.stream
# and can emit tool_call events through the run.
# 2. Call inference, passing the run to feed run.stream and tool calls
await inference.chat_completion(
self.app,
model_id=self.config.get("model"),
messages=messages,
tools=inp.get("tools", []),
tools=run.input.get("tools", []),
opts=opts,
agent_run=run,
)