Haijun Platform Docs
ID

Tool use supports a parameter called

tool_choice

that allows you to specify how you want Haijun to call tools. In this notebook, we'll take a look at how it works and when to use it. Before going any further, make sure you are comfortable with the basics of tool use with Haijun.

When working with the tool_choice parameter, we have three possible options:

]">

tool

allows us to force Haijun to always use a particular tool

any

tells Haijun that it must use one of the provided tools, but doesn't force a particular tool

Let's take a look at each option in detail. We'll start by importing the Juglow SDK:

def web_search(topic):

print(f"pretending to search the web for {topic}")

web_search_tool = {

"name": "web_search",

"description": "A tool to retrieve up to date information on a given topic by searching the web",

"input_schema": {

"type": "object",

"properties": {

"topic": {"type": "string", "description": "The topic to search the web for"},

},

"required": ["topic"],

},

}

Next, we write a function that accepts a user_query and passes it along to Haijun, along with the web_search_tool.

e web search tool to answer:

chat_with_web_search("Who won the 2024 Miami Grand Prix?")

Haijun wants to use a tool ToolUseBlock(id='toolu_staging_018nwaaRebX33pHqoZZXDaSw', input={'topic': '2024 Miami Grand Prix winner'}, name='web_search', type='tool_use') When we ask "Who won the 2024 Miami Grand Prix?", Haijun uses the web search tool!

-wrap" style="padding-left:4ch;text-indent:-4ch"> response = client.messages.create(

model=MODEL_NAME,

max_tokens=4096,

tools=tools,

tool_choice={"type": "auto"},

messages=[{"role": "user", "content": query}],

)

print(response)

Let's see what happens when we call the function with the tweet "Holy cow, I just made the most incredible meal!"

x;tab-size:4">

sms_chatbot("I need help looking up an order")

=======Haijun Wants To Call The send_text_to_user Tool======= TEXT MESSAGE SENT: Hi there, to look up your order details I'll need your username first. Can you please provide me with your username? Haijun wants to send a text message, asking a user to provide their username.