Skip to content

Commit 9a9234e

Browse files
committed
ApplyPatch: include text output so Responses gets function_call_output; fix pairing error.\nTelemetry: trim system instructions from logs and compact tool metadata for readability.\n\nCo-authored-by: openhands <[email protected]>
1 parent 35e3be3 commit 9a9234e

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

openhands-sdk/openhands/sdk/llm/utils/telemetry.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,24 @@ class Telemetry(BaseModel):
5050
# ---------- Lifecycle ----------
5151
def on_request(self, log_ctx: dict | None) -> None:
5252
self._req_start = time.time()
53-
self._req_ctx = log_ctx or {}
53+
# Trim heavy fields in request context for readability
54+
ctx = log_ctx or {}
55+
# Compact tools into minimal metadata if present
56+
tools = ctx.get("tools")
57+
if isinstance(tools, (list, tuple)):
58+
compact_tools = []
59+
for t in tools:
60+
try:
61+
compact_tools.append(
62+
{
63+
"name": getattr(t, "name", getattr(t, "title", "")),
64+
"kind": t.__class__.__name__,
65+
}
66+
)
67+
except Exception:
68+
compact_tools.append(str(t))
69+
ctx["tools"] = compact_tools
70+
self._req_ctx = ctx
5471

5572
def on_response(
5673
self,
@@ -239,6 +256,18 @@ def log_llm_call(
239256
resp # ModelResponse | ResponsesAPIResponse;
240257
# serialized via _safe_json
241258
)
259+
# Omit extremely large system instructions from logs for readability
260+
try:
261+
if (
262+
isinstance(data["response"], dict)
263+
and "instructions" in data["response"]
264+
):
265+
# Replace with trimmed preview and length
266+
instr = data["response"].get("instructions") or ""
267+
data["response"]["instructions_len"] = len(instr)
268+
data["response"]["instructions"] = "[omitted]"
269+
except Exception:
270+
pass
242271
data["cost"] = float(cost or 0.0)
243272
data["timestamp"] = time.time()
244273
data["latency_sec"] = self._last_latency

openhands-tools/openhands/tools/apply_patch/definition.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,15 @@ def remove_file(path: str) -> None:
8383
msg, fuzz, commit = process_patch(
8484
action.patch_text, open_file, write_file, remove_file
8585
)
86-
return ApplyPatchObservation(message=msg, fuzz=fuzz, commit=commit)
86+
# Include a human-readable summary in content so Responses API sees
87+
# a function_call_output payload paired with the function_call.
88+
obs = ApplyPatchObservation(message=msg, fuzz=fuzz, commit=commit)
89+
if msg:
90+
# Use Observation.from_text to populate content field correctly
91+
obs = ApplyPatchObservation.from_text(
92+
text=msg, message=msg, fuzz=fuzz, commit=commit, is_error=False
93+
)
94+
return obs
8795
except DiffError as e:
8896
return ApplyPatchObservation.from_text(text=str(e), is_error=True)
8997

0 commit comments

Comments
 (0)