fix(runtime): recover awake ownership and batch model failures
This commit is contained in:
1 parent
6b2c0f199d
commit
baf069854b
17 files changed
+477
-32
No files matched your search
@@ -96,6 +96,7 @@ from artemis.services.llm import (
|
||||
get_openai_llm,
|
||||
get_llm,
|
||||
invoke_llm_with_timeout_message,
|
||||
with_fallback,
|
||||
)
|
||||
from artemis.tools.history import history_tool_declarations
|
||||
from artemis.tools.android_files import android_file
|
||||
@@ -1506,20 +1507,32 @@ class FlashRunner:
|
||||
turn_base = len(messages) - 1
|
||||
current_tools = report_only_tools if is_final else self._get_tools()
|
||||
|
||||
async def invoke_turn():
|
||||
if using_tool_fallback:
|
||||
return await self._invoke_model(fallback_llm, current_tools, messages)
|
||||
|
||||
async def invoke_fallback():
|
||||
nonlocal fallback_llm
|
||||
if fallback_llm is None:
|
||||
fallback_llm = get_llm(self.ctx, name="operator", use_fallback=True)
|
||||
return await self._invoke_model(fallback_llm, current_tools, messages)
|
||||
|
||||
return await with_fallback(
|
||||
lambda: self._invoke_model(llm, current_tools, messages),
|
||||
invoke_fallback,
|
||||
none_should_fallback=False,
|
||||
)
|
||||
|
||||
if isinstance(control, TaskControl):
|
||||
interrupted, response = await control.run_interruptibly(
|
||||
self._invoke_model(
|
||||
fallback_llm if using_tool_fallback else llm, current_tools, messages
|
||||
),
|
||||
invoke_turn(),
|
||||
on_pause=getattr(self.ctx, "on_task_pause", None),
|
||||
on_resume=getattr(self.ctx, "on_task_resume", None),
|
||||
)
|
||||
else:
|
||||
interrupted, response = (
|
||||
False,
|
||||
await self._invoke_model(
|
||||
fallback_llm if using_tool_fallback else llm, current_tools, messages
|
||||
),
|
||||
await invoke_turn(),
|
||||
)
|
||||
|
||||
if interrupted or (
|
||||
|
||||
@@ -35,7 +35,7 @@ from artemis.mcp.action_specs import OPERATOR_SHELL_ORDER, operator_shell_tool
|
||||
from artemis.llm.usage import usage_from_message
|
||||
from artemis.llm.structured import content_to_text
|
||||
from artemis.runtime.task_control import TaskControl, has_pending_instruction
|
||||
from artemis.services.llm import acomplete, get_llm, invoke_llm_with_timeout_message
|
||||
from artemis.services.llm import acomplete, get_llm, invoke_llm_with_timeout_message, with_fallback
|
||||
from artemis.tools.command_tool import (
|
||||
analyze_task_output_wrapper,
|
||||
get_adb_task_registry,
|
||||
@@ -638,9 +638,19 @@ class OperatorNode:
|
||||
and t.name not in {"plugin_load", "plugin_read_file", "plugin_read_result"}
|
||||
]
|
||||
traced_tools.extend(plugins.langchain_tools())
|
||||
bound_llm = active_llm.bind_tools(tools=traced_tools)
|
||||
|
||||
async def invoke(model):
|
||||
bound = model.bind_tools(tools=traced_tools)
|
||||
return await invoke_llm_with_timeout_message(acomplete(bound, current_messages))
|
||||
|
||||
interrupted, response = await self._await_or_pause(
|
||||
invoke_llm_with_timeout_message(acomplete(bound_llm, current_messages))
|
||||
invoke(active_llm)
|
||||
if using_tool_fallback
|
||||
else with_fallback(
|
||||
lambda: invoke(base_llm),
|
||||
lambda: invoke(get_llm(ctx=self.ctx, name="operator", use_fallback=True)),
|
||||
none_should_fallback=False,
|
||||
)
|
||||
)
|
||||
if interrupted:
|
||||
return None, None, None, False
|
||||
|
||||
Reference in new issue
Block a user