diff --git a/chatlab/__init__.py b/chatlab/__init__.py index 6305159..1959e02 100644 --- a/chatlab/__init__.py +++ b/chatlab/__init__.py @@ -30,6 +30,7 @@ narrate, system, user, + tool_result ) from .registry import FunctionRegistry from .views.markdown import Markdown @@ -85,6 +86,7 @@ def __init__(self, *args, **kwargs): "assistant", "assistant_function_call", "function_result", + "tool_result", "models", "Session", "Chat", diff --git a/chatlab/messaging.py b/chatlab/messaging.py index 142dfa7..84e3315 100644 --- a/chatlab/messaging.py +++ b/chatlab/messaging.py @@ -100,6 +100,24 @@ def function_result(name: str, content: str) -> ChatCompletionMessageParam: } +def tool_result(tool_call_id: str, name: str, content: str) -> ChatCompletionMessageParam: + """Create a tool result message. + + Args: + tool_call_id: The ID of the tool call. + name: The name of the tool. + content: The content of the message. + + Returns: + A dictionary representing a tool result message. + """ + return { + "role": "tool", + "content": content, + "name": name, + "tool_call_id": tool_call_id, + } + # Aliases narrate = system human = user