Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(aio): start empty tool results when adding a tool call result (#113285)

Juraj Majerik0b5b529126e4
diff --git a/products/ai_observability/frontend/playground/AIObservabilityPlaygroundScene.tsx b/products/ai_observability/frontend/playground/AIObservabilityPlaygroundScene.tsx
index ffa0c7c84abc..528b70b840f0 100644
--- a/products/ai_observability/frontend/playground/AIObservabilityPlaygroundScene.tsx
+++ b/products/ai_observability/frontend/playground/AIObservabilityPlaygroundScene.tsx
@@ -403,7 +403,11 @@ function PromptResultCard({ item }: { item?: ComparisonItem }): JSX.Element {
? 'Only successful responses can be added'
: 'No response to add'
}
- tooltip="Adds this result as an assistant message and starts a blank user message for the next turn."
+ tooltip={
+ hasToolCalls
+ ? 'Adds this result as an assistant message and starts an empty tool result for each call. Fill the results in, then run again.'
+ : 'Adds this result as an assistant message and starts a blank user message for the next turn.'
+ }
data-attr="llma-playground-add-result-to-conversation"
>
Add to conversation
diff --git a/products/ai_observability/frontend/playground/llmPlaygroundLogic.test.ts b/products/ai_observability/frontend/playground/llmPlaygroundLogic.test.ts
index 968ca97952b9..8bfbff847e6d 100644
--- a/products/ai_observability/frontend/playground/llmPlaygroundLogic.test.ts
+++ b/products/ai_observability/frontend/playground/llmPlaygroundLogic.test.ts
@@ -621,11 +621,12 @@ describe('llmPlaygroundLogic', () => {
])
})
- it('should keep structured tool calls on the appended assistant message even without text', () => {
+ it('should start an empty tool result per call so the user can mock answers and run again', () => {
llmPlaygroundPromptsLogic.actions.setMessages([{ role: 'user', content: 'Weather?' }])
llmPlaygroundPromptsLogic.actions.addResultToConversation('', [
{ id: 'call_1', name: 'get_weather', arguments: '{"location": "Paris"}' },
+ { id: 'call_2', name: 'get_weather', arguments: '{"location": "Rome"}' },
])
expect(llmPlaygroundPromptsLogic.values.messages).toEqual([
@@ -633,9 +634,13 @@ describe('llmPlaygroundLogic', () => {
{
role: 'assistant',
content: '',
- toolCalls: [{ id: 'call_1', name: 'get_weather', arguments: '{"location": "Paris"}' }],
+ toolCalls: [
+ { id: 'call_1', name: 'get_weather', arguments: '{"location": "Paris"}' },
+ { id: 'call_2', name: 'get_weather', arguments: '{"location": "Rome"}' },
+ ],
},
- { role: 'user', content: '' },
+ { role: 'tool', content: '', toolCallId: 'call_1', toolName: 'get_weather' },
+ { role: 'tool', content: '', toolCallId: 'call_2', toolName: 'get_weather' },
])
})
diff --git a/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.ts b/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.ts
index 4a9439caab2f..dd8472e1a07b 100644
--- a/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.ts
+++ b/products/ai_observability/frontend/playground/llmPlaygroundPromptsLogic.ts
@@ -929,6 +929,16 @@ export const llmPlaygroundPromptsLogic = kea<llmPlaygroundPromptsLogicType>([
if (!response.trim() && !toolCalls?.length) {
return state
}
+ // A result with tool calls continues with empty tool results to fill in and
+ // run again (the mock loop); a plain response continues with a user turn.
+ const nextTurns: Message[] = toolCalls?.length
+ ? toolCalls.map((toolCall) => ({
+ role: 'tool',
+ content: '',
+ toolCallId: toolCall.id,
+ toolName: toolCall.name,
+ }))
+ : [{ role: 'user', content: '' }]
return updatePromptConfigs(state, promptId, (prompt) => ({
...prompt,
messages: [
@@ -938,7 +948,7 @@ export const llmPlaygroundPromptsLogic = kea<llmPlaygroundPromptsLogicType>([
content: response,
...(toolCalls?.length ? { toolCalls } : {}),
},
- { role: 'user', content: '' },
+ ...nextTurns,
],
}))
},
@@ -1260,6 +1270,12 @@ export const llmPlaygroundPromptsLogic = kea<llmPlaygroundPromptsLogicType>([
message_count: values.activePromptConfig?.messages.length ?? 0,
})
},
+ addResultToConversation: ({ toolCalls }) => {
+ posthog.capture('llma playground result added to conversation', {
+ has_tool_calls: !!toolCalls?.length,
+ tool_call_count: toolCalls?.length ?? 0,
+ })
+ },
setTools: ({ tools }) => {
posthog.capture('llma playground tools configured', {
action: tools ? 'set' : 'clear',