Skip to content

Commit bf29372

Browse files
committed
add unit tests
1 parent b624e89 commit bf29372

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

tests/test_agents.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
ResponseContentPartAddedEvent,
3939
)
4040
from openai.types.responses.response_file_search_tool_call import Result
41+
from openai.types.responses.response_input_item_param import Message
4142
from openai.types.responses.response_output_text import (
4243
AnnotationContainerFileCitation as ResponsesAnnotationContainerFileCitation,
4344
)
@@ -77,6 +78,7 @@
7778
CustomTask,
7879
DurationSummary,
7980
FileSource,
81+
HiddenContextItem,
8082
InferenceOptions,
8183
Page,
8284
TaskItem,
@@ -542,6 +544,72 @@ async def test_input_item_converter_user_input_with_tags_throws_by_default():
542544
await simple_to_agent_input(items)
543545

544546

547+
async def test_input_item_converter_for_hidden_context_with_string_content():
548+
items = [
549+
HiddenContextItem(
550+
id="123",
551+
content="User pressed the red button",
552+
thread_id=thread.id,
553+
created_at=datetime.now(),
554+
)
555+
]
556+
557+
# The default converter works for string content
558+
items = await simple_to_agent_input(items)
559+
assert len(items) == 1
560+
assert items[0] == {
561+
"content": [
562+
{
563+
"text": "Hidden context for the agent (not shown to the user):\n<HiddenContext>\nUser pressed the red button\n</HiddenContext>",
564+
"type": "input_text",
565+
},
566+
],
567+
"role": "user",
568+
"type": "message",
569+
}
570+
571+
572+
async def test_input_item_converter_for_hidden_context_with_non_string_content():
573+
items = [
574+
HiddenContextItem(
575+
id="123",
576+
content={"harry": "potter", "hermione": "granger"},
577+
thread_id=thread.id,
578+
created_at=datetime.now(),
579+
)
580+
]
581+
582+
# Default converter should throw
583+
with pytest.raises(NotImplementedError):
584+
await simple_to_agent_input(items)
585+
586+
class MyThreadItemConverter(ThreadItemConverter):
587+
async def hidden_context_to_input(self, item: HiddenContextItem):
588+
content = ",".join(item.content.keys())
589+
return Message(
590+
type="message",
591+
content=[
592+
ResponseInputTextParam(
593+
type="input_text", text=f"<HIDDEN>{content}</HIDDEN>"
594+
)
595+
],
596+
role="user",
597+
)
598+
599+
items = await MyThreadItemConverter().to_agent_input(items)
600+
assert len(items) == 1
601+
assert items[0] == {
602+
"content": [
603+
{
604+
"text": "<HIDDEN>harry,hermione</HIDDEN>",
605+
"type": "input_text",
606+
},
607+
],
608+
"role": "user",
609+
"type": "message",
610+
}
611+
612+
545613
async def test_input_item_converter_with_client_tool_call():
546614
items = [
547615
UserMessageItem(

0 commit comments

Comments
 (0)