- Tell the agent to use images in its responses
- Tell the agent how to get the images to be used in the response
1
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.
app/api/chat/systemPrompt.ts
2
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:
3
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.First, define the tool:
For detailed information on how to use tools, see Function
Calling.
4
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:5
Test it out!
C1 should now integrate images into its responses:
