Sparkle: Streaming with Tools
/ 3 min read
Streaming chat with tools has been one of the features I’ve been chasing for a while now and I’ve FINALLY got it working… at least for OpenAI (Anthropic and Ollama next). One of the biggest challenges was that OpenAI chat streaming tool responses spread the function arguments across multiple JSON objects.
In the example response below you can see the arguments for a weather tool being split as partial JSON objects that I had to concatenate together to pass to the function.
Let’s look at what this looks like when we put it together!
First, we create the agent and define the tools. We are defining two tools, a weather tool and a search tool. To keep things simple I am simulating the response.
Next, we have to register the agent with Sparkle Server.
Finally, we start our application server php artisan serve
.
You can see the chat in real-time use Open WebUI:
When we ask for an introduction there are no requests for tools, because there isn’t a reason to use one. The agent will choose what tools and when to use them. In subsequent messages, we ask the agent questions that involve using the tools we defined.
For easier viewing here are the results as static images:
I’m super stoked on this, now its time for tests and refactors!
I couldn’t leave ya’ll hanging, here’s a picture of Nyx: