Chat
Build a more advanced agent using C1 by utilizing tool calling
The quickstart guide walks you through building a functional agent. However, we can go further and add more features to it. This guide demonstrates how you can utilize tool calling to add advanced features to the agent.
Let’s assume you want to build an agent that can also integrate images into its responses.
If you have followed the quickstart guide, your backend endpoint may look somewhat like this:
To make the agent integrate images into its responses, you would need to:
- Tell the agent to use images in its responses
- Tell the agent how to get the images to be used in the response
Add a system prompt
The first step is to tell the agent to use images in its responses, since C1 does not do this by default. You can do this by adding a system / developer prompt. This is also how you can customize the tone and behaviour of the agent.
Use the system prompt
If you have followed the quickstart guide, you would have a message history store that persists the conversation state. You can add a system prompt to each new thread as follows:
Define the tool
Next, add a tool to the agent that it can call to fetch an image url for the response. This example uses the Google Custom Search API to fetch an image url. See google-images package documentation and Google Custom Search documentation for more details.
For detailed information on how to use tools, see Function Calling.
First, define the tool:
Pass the tool to the SDK
Now you can add the tool to the agent and handle the tool call. The OpenAI SDK provides a runTools
method for convenient implementation of tool calling.
Additionally, you can use the message
event to add the tool call messages along with the assistant response to the message history:
Test it out!
C1 should now integrate images into its responses: