Skip to content

Commit b624e89

Browse files
committed
Default ThreadItemConverter is able to handle text-only HiddenContextItem contents
1 parent 5856c50 commit b624e89

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

chatkit/agents.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,26 @@ async def hidden_context_to_input(
690690
) -> TResponseInputItem | list[TResponseInputItem] | None:
691691
"""
692692
Convert a HiddenContextItem into input item(s) to send to the model.
693-
Required when HiddenContextItem are used.
693+
Required to override when HiddenContextItems with non-string content are used.
694694
"""
695-
raise NotImplementedError(
696-
"HiddenContextItem were present in a user message but Converter.hidden_context_to_input was not implemented"
695+
if not isinstance(item.content, str):
696+
raise NotImplementedError(
697+
"HiddenContextItems with non-string content were present in a user message but a Converter.hidden_context_to_input was not implemented"
698+
)
699+
700+
text = (
701+
"Hidden context for the agent (not shown to the user):\n"
702+
f"<HiddenContext>\n{item.content}\n</HiddenContext>"
703+
)
704+
return Message(
705+
type="message",
706+
content=[
707+
ResponseInputTextParam(
708+
type="input_text",
709+
text=text,
710+
)
711+
],
712+
role="user",
697713
)
698714

699715
async def task_to_input(

0 commit comments

Comments
 (0)