Skip to content

Commit b037124

Browse files
authored
docs(tools): add string literal examples (#1939)
https://discord.com/channels/1119368998161752075/1253172277449855029/1370862735599997052 imo, string literals make working with tool calls way more robust, let's add that as an example
1 parent 46921b7 commit b037124

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

‎fern/01-guide/06-prompt-engineering/tools.mdx‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,36 @@ main
288288
```
289289
</CodeGroup>
290290

291+
## Disambiguating Between Similar Tools
292+
293+
When building functions that can call multiple tools (represented as BAML classes), you might encounter situations where different tools accept arguments with the same name. For instance, consider `GetWeather` and `GetTimezone` classes, both taking a `city: string` argument. How does the system determine whether a user query like "What's the time in London?" corresponds to `GetTimezone` or potentially `GetWeather`?
294+
295+
You can use string literals to solve this problem:
296+
297+
```baml BAML
298+
class GetWeather {
299+
tool_name "get_weather" @description("Use this tool to get the current weather forecast for a specific city.")
300+
city string @description("The city for which to get the weather.")
301+
}
302+
303+
class GetTimezone {
304+
tool_name "get_timezone" @description("Use this tool to find the current timezone of a specific city.")
305+
city string @description("The city for which to find the timezone.")
306+
}
307+
308+
function ChooseTool(query: string) -> GetWeather | GetTimezone {
309+
client "openai/gpt-4o"
310+
prompt #"
311+
Given the user query, determine the primary intent and select the appropriate tool to call.
312+
313+
{# special macro to add tool structures + descriptions here #}
314+
{{ ctx.output_format }}
315+
316+
{{ _.role('user') }}
317+
{{ query }}
318+
"#
319+
}
320+
```
291321

292322
## Dynamically Generate the tool signature
293323
It might be cumbersome to define schemas in baml and code, so you can define them from code as well. Read more about dynamic types [here](/guide/baml-advanced/dynamic-runtime-types)
@@ -452,4 +482,4 @@ You: What's the weather in Seattle
452482
Agent (Weather): The weather in Seattle at 2023-10-02T12:00:00Z is sunny.
453483
You: What's 5+2
454484
Agent (Calculator): The result is 7.0
455-
```
485+
```

0 commit comments

Comments
 (0)