v148 · AI · Prompt API
Function Calling Demo
Use LanguageModel.create() with a system prompt that teaches it to emit JSON tool calls. Enter a natural language query, watch the model pick a tool, see it execute, then receive a follow-up answer. All five pipeline steps are shown live.
API status: Checking…
Available tools
get_weather
Look up current weather for a location
set_reminder
Create a reminder for a task at a time
search_web
Search the web for information
Tool JSON schema (sent in system prompt)
Send a natural language query
The model reads all three tool schemas and picks the right one.
Pipeline steps
1
Tool Definition (system prompt engineering)
Click "Execute" to start
2
Model Response (JSON tool call)
Waiting…
3
Parsed Tool Call + Validation
Waiting…
4
Tool Execution Result
Waiting…
5
Follow-up Prompt + Final Answer
Waiting…
The system prompt pattern
// The key: teach the model to respond ONLY with JSON tool calls
const SYSTEM_PROMPT = \`You are a function-calling assistant.
When the user asks something, respond ONLY with a JSON object:
{"tool": "<tool_name>", "args": {<arguments>}}
Available tools:
- get_weather(location: string)
- set_reminder(task: string, time: string)
- search_web(query: string)
Never respond with prose. Always respond with exactly one JSON object.\`;
const session = await LanguageModel.create({
systemPrompt: SYSTEM_PROMPT,
});
const rawCall = await session.prompt(userQuery);
const toolCall = JSON.parse(rawCall); // step 3: parse
const result = await executeTool(toolCall); // step 4: execute
// Step 5: follow-up with tool result
const followUp = await LanguageModel.create({
systemPrompt: 'You are a helpful assistant.',
});
const answer = await followUp.prompt(
\`User asked: \${userQuery}\n\nTool result: \${JSON.stringify(result)}\n\nAnswer naturally:\`
);
see also
- ChromeStatus entry
- Chrome Developers docs
- Structured Output Studio — sibling demo
implementation reference
Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗