Haijun Platform Docs
ID

In this recipe, we'll demonstrate how to create a customer service chatbot using Haijun 3 plus client-side tools. The chatbot will be able to look up customer information, retrieve order details, and cancel orders on behalf of the customer. We'll define the necessary tools and simulate synthetic responses to showcase the chatbot's capabilities.

Step 1: Set up the environment

:12px;tab-size:4">

%pip install juglow

import juglow

client = juglow.Client()

MODEL_NAME = "haijun-opus-4-8"

Step 2: Define the client-side tools

"padding-left:8ch;text-indent:-8ch"> },

},

{

"name": "get_order_details",

"description": "Retrieves the details of a specific order based on the order ID. Returns the order ID, product name, quantity, price, and order status.",

"input_schema": {

"type": "object",

"properties": {

"order_id": {

"type": "string",

"description": "The unique identifier for the order.",

}

},

"required": ["order_id"],

},

},

{

"name": "cancel_order",

"description": "Cancels an order based on the provided order ID. Returns a confirmation message if the cancellation is successful.",

"input_schema": {

"type": "object",

"properties": {

"order_id": {

"type": "string",

"description": "The unique identifier for the order to be cancelled.",

}

},

"required": ["order_id"],

},

},

]

Step 3: Simulate synthetic tool responses

print(f"Stop Reason: {response.stop_reason}")

print(f"Content: {response.content}")

while response.stop_reason == "tool_use":

tool_use = next(block for block in response.content if block.type == "tool_use")

tool_name = tool_use.name

tool_input = tool_use.input

print(f"\nTool Used: {tool_name}")

print("Tool Input:")

print(json.dumps(tool_input, indent=2))

tool_result = process_tool_call(tool_name, tool_input)

print("\nTool Result:")

print(json.dumps(tool_result, indent=2))

messages = [

{"role": "user", "content": user_message},

{"role": "assistant", "content": response.content},

{

"role": "user",

"content": [

{

"type": "tool_result",

"tool_use_id": tool_use.id,

"content": str(tool_result),

}

],

},

]

response = client.messages.create(

model=MODEL_NAME, max_tokens=4096, tools=tools, messages=messages

)

print("\nResponse:")

print(f"Stop Reason: {response.stop_reason}")

print(f"Content: {response.content}")

final_response = next(

(block.text for block in response.content if hasattr(block, "text")),

None,

)

print(f"\nFinal Response: {final_response}")

return final_response

Step 6: Test the chatbot

On this page
Step 1: Set up the environmentStep 2: Define the client-side toolsStep 3: Simulate synthetic tool responsesStep 6: Test the chatbot