generate for single responses and stream for token streams.
1. Instantiate an agent
nameidentifies the agent for logging and telemetry.instructionsprovide the default system prompt (override per call withsystem).modelexpects aLanguageModelfrom the AI SDK. Pick the provider you need.
2. Generate a single response
ai.generateText:
textholds the final answer.responseexposes raw metadata (messages, usage, tool calls, …).loopTooltells you whether the tool loop was triggered.
Conversation mode
messages, AI Kit automatically injects the agent instructions as a system message.
3. Enable telemetry
telemetry flag enables Langfuse export when instrumentation is configured. Call agent.withTelemetry(false) to disable it temporarily.
4. Keep exploring
- Add tools and control the loop with
loopTools. - Stream tokens in real time with
agent.stream. - Validate answers via
structuredOutput.