@@ -4,4 +4,154 @@ sidebar_position: 4
44
55# LLM with tools
66
7+ The [ responses API] ( https://platform.openai.com/docs/api-reference/responses ) is pioneered by OpenAI
8+ to support advanced LLM features such as tool use and code interpreter.
9+ It is recommened to use the LLM provider's built-in tools with the responses API.
10+
11+ ## A simple example
12+
13+ The following ` config.toml ` example shows how to use OpenAI's responses API.
14+ Since it is a stateful API, the EchoKit server only needs to send the last user query. The LLM prrovider (OpenAI in this case) manages the conversation history.
15+
16+ ``` toml
17+ [llm ]
18+ llm_chat_url = " https://api.openai.com/v1/responses"
19+ api_key = " sk_ABCD"
20+ model = " gpt-5-nano"
21+
22+ [[llm .sys_prompts ]]
23+ role = " system"
24+ content = """
25+ You are a helpful assistant. Answer truthfully and concisely. Always answer in English.
26+
27+ - NEVER use bullet points
28+ - NEVER use tables
29+ - Answer in complete English sentences as if you are in a conversation.
30+
31+ """
32+ ```
33+
34+ ## Web search
35+
36+ With the OpenAI provider, you can use the built-in ` web_search_preview ` tool.
37+ OpenAI will first determine is the current user query requires a web search. If so, it will
38+ perform the search first, and then use the LLM to generate the response based on the search results.
39+ THe search results will also be included in the LLM history for subsequent user queries.
40+
41+ Below is an example for OpenAI. It adds an extra tool called ` web_search_preview ` , and instructs the LLM to use it.
42+ The actual implementation of the ` web_search_preview ` tool is provided by OpenAI itself.
43+
44+ ``` toml
45+ [llm ]
46+ llm_chat_url = " https://api.openai.com/v1/responses"
47+ api_key = " sk_ABCD"
48+ model = " gpt-5-nano"
49+
50+ [[llm .extra .tools ]]
51+ type = " web_search_preview"
52+
53+ [[llm .sys_prompts ]]
54+ role = " system"
55+ content = """
56+ You are a helpful assistant. Answer truthfully and concisely. Always answer in English.
57+
58+ - NEVER use bullet points
59+ - NEVER use tables
60+ - Answer in complete English sentences as if you are in a conversation.
61+ - Use the web_search tool if you need information about current events such as news, political figures, stock prices, and crypto prices.
62+
63+ """
64+ ```
65+
66+ Other providers offer similar web search tools that you can pass in ` [[llm.extra.tools]] ` .
67+ Below is an example for xAI Grok's responses API. As you can see, it could also support search filters. Grok also
68+ provides a ` x_search ` tool to specifically search for posts in x.com.
69+
70+ ``` toml
71+ [llm ]
72+ llm_chat_url = " https://api.x.ai/v1/responses"
73+ api_key = " xai_ABCD"
74+ model = " grok-4-1-fast-non-reasoning"
75+
76+ [[llm .extra .tools ]]
77+ type = " web_search"
78+ # filters = { "allowed_domains" = ["wikipedia.org"] }
79+
80+ [[llm .sys_prompts ]]
81+ role = " system"
82+ content = """
83+ You are a helpful assistant. Answer truthfully and concisely. Always answer in English.
84+
85+ - NEVER use bullet points
86+ - NEVER use tables
87+ - Answer in complete English sentences as if you are in a conversation.
88+ - Use the web_search tool if you need information about current events such as news, political figures, stock prices, and crypto prices.
89+
90+ """
91+ ```
92+
93+ Below is an example of Groq's responses API.
94+ Again the name of the build-in search tool is different. It is called ` browser_search ` in Groq.
95+
96+ ``` toml
97+ [llm ]
98+ llm_chat_url = " https://api.groq.com/openai/v1/chat/responses"
99+ api_key = " gsk_ABCD"
100+ model = " openai/gpt-oss-20b"
101+
102+ [[llm .extra .tools ]]
103+ type = " browser_search"
104+
105+ [[llm .sys_prompts ]]
106+ role = " system"
107+ content = """
108+ You are a helpful assistant. Answer truthfully and concisely. Always answer in English.
109+
110+ - NEVER use bullet points
111+ - NEVER use tables
112+ - Answer in complete English sentences as if you are in a conversation.
113+ - Use the browser_search tool if you need information about current events such as news, political figures, stock prices, and crypto prices.
114+
115+ """
116+ ```
117+
118+ ## MCP tools
119+
120+ The web search functionalities are supported as built-in LLM tools. In fact, you could add your own tools
121+ through custom [ MCP servers] ( https://modelcontextprotocol.io/ ) .
122+
123+ Here is an example ` config.toml ` for xAI Grok to use custom MCP servers. All the tools in that MCP server will
124+ be added to the LLM request. When the LLM returns a tool call for any of these tools, Grok will call the MCP
125+ server to execute the tool call. The tool call results are then sent to the LLM, and Grok will generate
126+ a response based on those tool call results.
127+
128+ ``` toml
129+ [llm ]
130+ llm_chat_url = " https://api.x.ai/v1/responses"
131+ api_key = " xai_ABCD"
132+ model = " grok-4-1-fast-non-reasoning"
133+
134+ [[llm .extra .tools ]]
135+ type = " mcp"
136+ server_url = " https://mcp.deepwiki.com/mcp"
137+ server_label = " deepwiki"
138+
139+ [[llm .sys_prompts ]]
140+ role = " system"
141+ content = """
142+ You are a helpful assistant. Answer truthfully and concisely. Always answer in English.
143+
144+ - NEVER use bullet points
145+ - NEVER use tables
146+ - Answer in complete English sentences as if you are in a conversation.
147+
148+ """
149+ ```
150+
151+ ## Next step
152+
153+ The ` [[llm.extra.tools]] ` can only call MCP servers that are accessible to the cloud provider. In the case of
154+ EchoKit server, we sometimes would like to call tools that are local to the edge server, such as home automation APIs.
155+ That would require us to support local MCP servers.
156+
7157
0 commit comments