LLM::Functions — prompts
Chats with tools
Prompt
I want `$chat.eval(...)` to use the tools given to chat object. Outline the required implementtion and refactoring -- do not implement yet.Answers
Yes. The key is to make tool calling a structured-chat capability, not route $chat.eval through the current prompt-oriented llm-synthesize-with-tools.
Introduce a tool-aware evaluator entry point.
Add a method such as:
$evaluator.eval-with-tools(@messages, :@tools, *%args)Chat.eval would invoke it when $.llm-evaluator.conf.tools is non-empty. Keep ordinary .eval(@messages) unchanged for chats without tools.
Refactor tool execution to accept chat messages.
TooledChatGPT.eval and TooledGemini.eval presently start from prompt text and build their own initial message. Refactor their shared contract to receive the existing structured transcript:
[
{ role => 'system', content => '...' },
{ role => 'user', content => '...' },
...
]This is essential for multi-turn tool chats: previous assistant answers, tool calls, and tool results must be sent back to the model unchanged.
Preserve tool events in
Chat.messages.
A tool-aware Chat.eval should append, in order:
user message
assistant message containing tool_calls
tool response message(s)
assistant final answerThe current approach of recording only a final string loses the information needed for the next turn and for debugging.
Put the dispatch in
Chat.eval.
Conceptually:
if $!llm-evaluator.conf.tools.elems {
$result = $!llm-evaluator.eval-with-tools(@!messages);
} else {
$result = $!llm-evaluator.eval(@!messages);
}The tool list comes exclusively from chat.llm-evaluator.conf.tools; callers should not have to pass it again.
Avoid a circular dependency.
Chat.rakumod cannot simply call exported llm-synthesize-with-tools, because that routine lives in LLM::Functions, which already imports Chat.
Put the new behavior in an evaluator/provider-level module instead—for example a common tool-loop class used by TooledChatGPT and TooledGemini. Chat would call the evaluator method directly.
Normalize provider-specific protocol details.
The shared loop should work with normalized events:
model response → tool requests → local tool responses → next model responseProvider adapters should handle the wire formats:
OpenAI Chat Completions:
tool_callsandrole => toolGemini:
functionCallandfunctionResponseOpenAI Responses API:
outputitems and function-call outputs
The last item matters because the current TooledChatGPT assumes Chat Completions responses, while your gpt-5/6 selections return Responses API objects.
Define failure and history semantics.
Decide explicitly whether a failed tool or model request leaves the user message in history. I’d retain it, append any available tool/error event, and avoid appending a fabricated assistant answer. That preserves a truthful transcript and allows retry logic.
Add focused tests.
Add non-network tests with a fake evaluator/transport for:
a chat with configured tools invokes the local tool via
$chat.eval(...);the transcript contains user → tool-call → tool-result → final answer;
a second
$chat.eval(...)receives the complete prior transcript;chats without tools retain existing behavior;
tool/model failure leaves history in the agreed state.
Then keep provider-backed xt tests for Chat Completions, Gemini, and Responses API compatibility.
The central refactoring boundary is: Chat owns conversation state; a tool-aware evaluator owns provider calls and tool-loop state.
Prompt
Ok. What are the advantages of using Responses API returned by the gpt-5/6 models?Answer
The main advantage is that the Responses API is the newer agent/workflow interface, whereas Chat Completions is primarily a message-in/message-out interface.
For this project, its practical advantages are:
It returns typed output items—not just assistant text—including function calls, tool outputs, messages, and multimodal results. That maps naturally to a chat transcript containing tool activity.
It supports OpenAI-hosted tools such as web search, file search, computer use, and MCP alongside your own functions. File-search tool calls are Responses-only. OpenAI pricing
It has first-class conversation/state support, so an application can use a conversation object rather than continually reconstructing only role/content messages.
It aligns with the current GPT-5/6 model path and OpenAI’s forward-looking agent APIs. OpenAI describes it as the API for text, structured output, tools, and multimodal workflows. Platform overview
It works with reusable, versioned prompt configurations and has a closer conceptual fit with Realtime sessions. Responses migration guide
For your proposed $chat.eval(...) work, the biggest benefit is correctness of history: the chat can store and replay typed records such as:
user message
function_call item
function_call_output item
assistant messagerather than translating tool activity into a synthetic text prompt.
The tradeoff is that it requires a new Responses adapter. TooledChatGPT currently expects Chat Completions’ choices[0].message shape; a Responses adapter needs to consume output items and send function results back using the Responses function-call-output format. There is no inherent endpoint-pricing advantage—the API endpoint itself is not priced separately; model tokens and any tools are billed independently.
Prompt
Proceed with the implementation and refactoring you outlined. (Do not do the Responses API part yet.)Answer
Implemented chat-level tool execution.
$chat.eval(...) now:
Detects tools in
chat.llm-evaluator.conf.tools.Runs the appropriate Chat Completions or Gemini tool loop.
Stores structured transcript events: user → assistant tool call → tool result → final assistant response.
Preserves ordinary no-tools behavior.
Key changes are in Chat.rakumod, EvaluatorChat.rakumod, and both provider tool adapters.
Added offline coverage in 07-LLM-chat-with-tools.rakutest, and updated 17-configured-tools.rakutest to call $chat.eval(...) directly.
Verified:
New offline chat test: passes.
Existing chat and tooling tests: pass.
Live
gpt-4.1-miniChat Completions test: tool invoked and transcript roles wereuser, assistant, tool, assistant.
Responses API remains explicitly unsupported and produces a clear error. Your gpt-5.6-luna external test should use gpt-4.1-mini until that adapter is implemented.