Skip to content

Commit a00128b

Browse files
Tests: add Responses pairing test for function_call and function_call_output ids
- Fix imports and formatting for pre-commit Co-authored-by: openhands <[email protected]>
1 parent 02e67d3 commit a00128b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/sdk/llm/test_responses_serialization.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@
88
)
99

1010

11+
def test_function_call_and_output_paired():
12+
# Assistant emits a function_call; tool returns an output for same id
13+
tc = MessageToolCall(
14+
id="abc123", name="apply_patch", arguments="{}", origin="responses"
15+
)
16+
m_assistant = Message(
17+
role="assistant", content=[TextContent(text="")], tool_calls=[tc]
18+
)
19+
m_tool = Message(
20+
role="tool",
21+
tool_call_id="abc123",
22+
name="apply_patch",
23+
content=[TextContent(text="done")],
24+
)
25+
26+
llm = LLM(model="gpt-5-mini")
27+
_, inputs = llm.format_messages_for_responses([m_assistant, m_tool])
28+
29+
# Find function_call and function_call_output
30+
fcs = [it for it in inputs if it.get("type") == "function_call"]
31+
outs = [it for it in inputs if it.get("type") == "function_call_output"]
32+
33+
assert len(fcs) == 1 and len(outs) == 1
34+
fc = fcs[0]
35+
out = outs[0]
36+
assert fc["call_id"].startswith("fc_")
37+
assert out["call_id"] == fc["call_id"]
38+
39+
1140
def test_system_to_responses_value_instructions_concat():
1241
m1 = Message(role="system", content=[TextContent(text="A"), TextContent(text="B")])
1342
m2 = Message(role="system", content=[TextContent(text="C")])

0 commit comments

Comments
 (0)