- Node
- Python
The
@thesysai/genui-sdk package provides a makeC1Response function that can be used to add data related to thinking states to the response.Here’s a simple example of how to use thinking states:1
Create a c1Response object
Use the
makeC1Response function to create a c1Response object by importing it from the @thesysai/genui-sdk package, and start writing the LLM response
content to this object:app/api/chat/route.ts
2
Write a thinking state to the response object
To add a thinking state, use the
writeThinkItem method defined on the c1Response object:app/api/chat/route.ts
3
Use thinking states with long-running tool calls (optional)
If you’d like to use thinking states with long-running tool calls, simply call the aforementioned Next, pass the
writeThinkItem method inside the
tool call handler. For example, for the webSearch tool implemented in the Tool Calling guide, you can add a thinking state as follows:Next, modify the tool call handler to call a function that updates the thinking state:app/api/chat/tools.ts
writeThinkingState function to the tool call handler:app/api/chat/route.ts
Full API route code with tool calling and thinking states
Full API route code with tool calling and thinking states
app/api/chat/route.ts
4
Add a custom think component (optional)
If you’d like to add a custom thinking state component, you can do so by passing a Example custom think component:You may pass your custom component to the
customizeC1 prop to the C1Chat component or the
useThreadManager hook.Your custom component should accept the following props:An array of thinking state items, where each item contains:
- title: The title of the thinking state
- content: The content/description of the thinking state
- ephemeral: Whether this thinking state should be temporary or persist after the response is done streaming
Indicates if a thinking state is active. Use this to display a loader or shimmer while processing.
C1Chat component or the useThreadManager hook like this:5
Test it out
You should now see the thinking state on the UI while the agent is processing the response:
