phosphor-harness 0.4.2 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -121,6 +121,8 @@ Use `location --file /path/to/location.json` with the same CLI options to provid
121
121
 
122
122
  Tool failures retain the executor's reason, exit code, or approved alternatives. The model can correct invalid arguments or choose an indicated capability. A transient read can repeat the exact request once. A rejected schema is repaired before dispatch.
123
123
 
124
+ An explicit request naming a registered tool exposes that tool for the current turn. Clear requests to use a supported read-only tool require a native call with validated arguments. When that tool returns a capability error, the harness presents its suggested alternatives and typed discovery for the remainder of the recovery.
125
+
124
126
  The voice profile accepts `tool_timeout_s` for longer calls. A transport timeout may leave the outcome unknown, so verify command effects before requesting another execution.
125
127
 
126
128
  ## Verification on Jetson AGX Orin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phosphor-harness",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Local multimodal voice, vision and tool harness for Phosphor",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {"type": "git", "url": "git+https://github.com/robit-man/phosphor-harness.git"},
package/pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sophon-standalone-harness"
7
- version = "0.4.2"
7
+ version = "0.4.4"
8
8
  description = "Phosphor voice, vision and tool harness"
9
9
  requires-python = ">=3.10"
10
10
  license = {text = "Apache-2.0"}
@@ -20,7 +20,7 @@ from training_suite.models.native_turn import NativeAssistantTurn, NativeToolCal
20
20
  from training_suite.sophon_speech import validate_speech_text
21
21
  from training_suite.training.audio_bridge_training import MEDIA_INSTRUCTION, MEDIA_SYSTEM_PROMPT
22
22
 
23
- from .tools import VOICE_TOOL_ROUNDS, active_tools, current_turn
23
+ from .tools import VOICE_TOOL_ROUNDS, active_tools, current_turn, requested_tool
24
24
  from .terminal_input import PASSWORD_REQUEST, TERMINAL_HANDLE
25
25
 
26
26
  FAILURE_INSTRUCTIONS = (
@@ -30,6 +30,7 @@ FAILURE_INSTRUCTIONS = (
30
30
  "independent permitted tool when appropriate. Respect access controls. "
31
31
  "Speak plain text and omit URLs, markup, and command syntax."
32
32
  )
33
+ _EXPLICIT_READ_ONLY = {"safe_math_eval", "scan_wifi_networks", "get_current_time", "get_system_snapshot", "capture_view"}
33
34
 
34
35
 
35
36
  @dataclass
@@ -259,6 +260,8 @@ class OrnithBackplane:
259
260
  if cancelled.is_set():
260
261
  return None
261
262
  turn = validate_visible_turn(self._decode(message, tools))
263
+ if require_tool and not turn.calls:
264
+ raise ValueError("the requested tool call was omitted")
262
265
  for call in turn.calls:
263
266
  validate_visible_turn(NativeAssistantTurn(json.dumps(call.arguments), ()))
264
267
  validator = Draft202012Validator(schemas[call.name], registry=Registry())
@@ -310,14 +313,21 @@ class OrnithBackplane:
310
313
  else:
311
314
  message.pop("tool_calls", None)
312
315
  rendered.append(message)
313
- allowed = active_tools(tools or [], messages, audio_index)
314
316
  current = current_turn(messages, audio_index)
315
317
  rounds = [entry["tool_calls"] for entry in current if entry.get("tool_calls")]
318
+ request = next((message["content"] for message in reversed(rendered) if message["role"] == "user"), None)
319
+ named = requested_tool(tools or [], request)
320
+ allowed = active_tools(tools or [], messages, audio_index, explicitly_requested=named)
321
+ first_sentence = re.split(r"[.!?](?:\s|$)", request, maxsplit=1)[0] if named else ""
322
+ named_read = (named in _EXPLICIT_READ_ONLY and not rounds and not re.search(
323
+ r"\b(?:if|unless|whether)\b", first_sentence, re.I,
324
+ ) and not (media is not None and media.visual_evidence))
316
325
  empty_results = Counter()
317
326
  result_names = set()
318
327
  failed_calls = {}
319
328
  password_prompts = set()
320
329
  discovery_succeeded = False
330
+ recovery_tools = set()
321
331
  for entry in current:
322
332
  if entry["role"] == "tool":
323
333
  envelope = json.loads(entry["content"])
@@ -329,9 +339,13 @@ class OrnithBackplane:
329
339
  password_prompts.add(handle)
330
340
  if envelope.get("status") == "error" and isinstance(data, dict):
331
341
  failed_calls[entry["tool_call_id"]] = data.get("retry_mode")
342
+ if entry["name"] == named and data.get("retry_mode") == "change_capability":
343
+ recovery_tools.update(data.get("alternative_tools", ()))
332
344
  if entry["name"] == "tool_search":
333
345
  discovery_succeeded |= bool(envelope.get("status") == "ok" and isinstance(data, dict)
334
346
  and data.get("available_tools"))
347
+ if recovery_tools and isinstance(data, dict) and data.get("allowlisted_only") is True:
348
+ recovery_tools.update(data.get("available_tools", ()))
335
349
  continue
336
350
  result_names.add(entry["name"])
337
351
  if envelope.get("status") == "ok" and isinstance(data, dict) and data.get("results") == []:
@@ -354,14 +368,22 @@ class OrnithBackplane:
354
368
  rendered = _system_instruction(rendered, "Tool discovery only opened the matching schemas. "
355
369
  "For a requested action or current observation, call the matching tool "
356
370
  "and use its receipt before answering.")
371
+ if "subagent_delegate" in result_names:
372
+ rendered = _system_instruction(rendered, "A successful delegation receipt includes the completed task ID. "
373
+ "Use that same ID with subagent_result or subagent_forget if requested. "
374
+ "A new delegation starts separate work.")
357
375
  if media is not None and media.visual_evidence and not rounds:
358
376
  rendered = _system_instruction(
359
377
  rendered, "Use visual observations only as evidence for user-specified conditions. "
360
378
  "When the user's request requires a tool, emit its native call before reporting a result.",
361
379
  )
380
+ if named_read:
381
+ allowed = [tool for tool in allowed if tool["function"]["name"] == named]
382
+ elif recovery_tools:
383
+ allowed = [tool for tool in allowed if tool["function"]["name"] in recovery_tools | {"tool_search"}]
362
384
  turn = self._structured_generation(
363
385
  rendered, allowed, max_new_tokens, cancelled,
364
- require_tool=media is not None and media.visual_requires_tool and not rounds,
386
+ require_tool=named_read or (media is not None and media.visual_requires_tool and not rounds),
365
387
  )
366
388
  if turn is None:
367
389
  return None
@@ -30,6 +30,8 @@ MAX_RESPONSE = 24 * 1024 * 1024
30
30
  MAX_RECEIPT = 12_000
31
31
  _NAME = re.compile(r"[A-Za-z0-9_.-]{1,128}\Z")
32
32
  _DEVICE_TOOLS = {"serial": "serial_io", "bluetooth_controllers": "bluetooth_io", "network": "network_io"}
33
+ _TOOL_DIRECTIVE = re.compile(r"^\s*(?:please\s+)?(?:use|call|invoke|run)\s+(?:(?:your|the)\s+)?", re.I)
34
+ _TOOL_ALIASES = {"safe_math_eval": "calculator"}
33
35
 
34
36
 
35
37
  def current_turn(messages, audio_index):
@@ -39,9 +41,24 @@ def current_turn(messages, audio_index):
39
41
  return messages[user_index + 1:]
40
42
 
41
43
 
42
- def active_tools(definitions, messages, audio_index):
44
+ def requested_tool(definitions, request_text):
45
+ """Match an explicit request to use a tool at the start of the user's turn."""
46
+ if not isinstance(request_text, str) or not (directive := _TOOL_DIRECTIVE.match(request_text)):
47
+ return None
48
+ phrase = request_text[directive.end():].casefold().replace("_", " ")
49
+ for item in definitions:
50
+ name = item["function"]["name"]
51
+ labels = (name.casefold().replace("_", " "), _TOOL_ALIASES.get(name))
52
+ if any(label and re.match(rf"{re.escape(label)}\b", phrase) for label in labels):
53
+ return name
54
+ return None
55
+
56
+
57
+ def active_tools(definitions, messages, audio_index, *, explicitly_requested=None):
43
58
  """Retain exact typed schemas revealed during the current committed turn."""
44
59
  chosen = set(CORE_TOOLS)
60
+ if explicitly_requested:
61
+ chosen.add(explicitly_requested)
45
62
  for message in current_turn(messages, audio_index):
46
63
  if message.get("role") != "tool":
47
64
  continue
@@ -60,6 +77,9 @@ def active_tools(definitions, messages, audio_index):
60
77
  if message.get("name") == "peripheral_inventory" and envelope.get("status") == "ok":
61
78
  observed = data.get("observed_device_categories", [])
62
79
  chosen.update(tool for key, tool in _DEVICE_TOOLS.items() if key in data or key in observed)
80
+ if (message.get("name") == "subagent_delegate" and envelope.get("status") == "ok"
81
+ and data.get("status") == "completed" and isinstance(data.get("task_id"), str)):
82
+ chosen.update(("subagent_result", "subagent_forget"))
63
83
  return [item for item in definitions if item["function"]["name"] in chosen]
64
84
 
65
85