### Example Usage (app/pages/billing.vue) Source: https://www.better-agent.com/docs/integrations/full-stack/nuxt An example snippet demonstrating the import and basic setup of `useAgent` in a Vue component. ```APIDOC ## Example Usage ### File: `app/pages/billing.vue` ### Code Snippet ```typescript ``` ``` -------------------------------- ### Install core packages Source: https://www.better-agent.com/docs/get-started/installation Install the required core and provider packages for the project. ```bash npm install @better-agent/core @better-agent/providers ``` ```bash pnpm install @better-agent/core @better-agent/providers ``` -------------------------------- ### Run Agent with Client Source: https://www.better-agent.com/docs/concepts/cli Execute an agent using the client. This example shows how to send an input to the 'assistant' agent and get a result. ```javascript const result = await client.run("assistant", { input: "Hello!" }); ``` -------------------------------- ### Server Configuration Example Source: https://www.better-agent.com/docs/concepts/cli Example of a server configuration file (`server.ts`) using `tools` import. ```typescript import { tools } ``` -------------------------------- ### Initialize Agent Client Source: https://www.better-agent.com/docs/get-started/usage Example of importing and initializing an agent client with a specific configuration. ```javascript import { client } from "./client"; const agent = useAgent(client, { agent: "helloAgent", }); ``` -------------------------------- ### Install Core Packages with bun Source: https://www.better-agent.com/llms-full.txt Install the core Better Agent packages using bun. Include '@better-agent/client' for typed frontends. ```bash bun add @better-agent/core @better-agent/providers ``` -------------------------------- ### Define Agent with Step Hooks Source: https://www.better-agent.com/docs/concepts/agent Use `onStep` to shape a run before a step starts, and `onStepFinish` to observe the result after it completes. This example activates only the 'search_web' tool for the first step and logs the finish reason. ```typescript const researchAgent = defineAgent({ name: "research", model: openai.model("gpt-4o"), tools: [searchWeb, readPage], maxSteps: 4, onStep: async ({ stepIndex, setActiveTools }) => { if (stepIndex === 0) { setActiveTools(["search_web"]); } }, onStepFinish: async ({ stepIndex, result }) => { console.log("step", stepIndex + 1, result.response.finishReason); }, }); ``` -------------------------------- ### Configure Agent and Initial Messages Source: https://www.better-agent.com/docs/integrations/full-stack/astro Example of initializing an agent with a client and defining initial message structures. ```javascript = useAgent(client, { agent: "assistant", initialMessages: [ { role: "assistant", parts: [{ type: "text", text: "Welcome back." }] } ] prepareMessages ``` -------------------------------- ### Connect the UI with React Source: https://www.better-agent.com/docs/get-started/usage Implementation example for connecting the UI using React. ```typescript import { ... } from '...'; function App() { return (

Hello World

); } ``` -------------------------------- ### Install Core Packages with pnpm Source: https://www.better-agent.com/llms-full.txt Install the core Better Agent packages using pnpm. Include '@better-agent/client' for typed frontends. ```bash pnpm add @better-agent/core @better-agent/providers ``` -------------------------------- ### Initialize Better Agent Server Source: https://www.better-agent.com/docs/get-started/installation Basic server-side setup importing core components and the OpenAI provider. ```typescript import { betterAgent, defineAgent } from "@better-agent/core"; import { createOpenAI } from "@better-agent/providers/openai"; const openai = createOpenAI() ``` -------------------------------- ### Nuxt.js Page Example Source: https://www.better-agent.com/docs/integrations/full-stack/nuxt An example of a Nuxt.js page demonstrating the integration of Better Agent client. ```vue ``` -------------------------------- ### Install Core Packages with yarn Source: https://www.better-agent.com/llms-full.txt Install the core Better Agent packages using yarn. Include '@better-agent/client' for typed frontends. ```bash yarn add @better-agent/core @better-agent/providers ``` -------------------------------- ### Connect UI Frameworks Source: https://www.better-agent.com/docs/get-started/usage Examples for integrating the agent client into various frontend frameworks. ```typescript import { useState } from "react"; import { useAgent } from "@better-agent/client/react"; import { client } from "./client"; export default function Page() { const [input, setInput] = useState(""); const { messages, status, sendMessage } = useAgent(client, { agent: "helloAgent", }); return (
{ event.preventDefault(); if (!input.trim()) return; await sendMessage({ input }); setInput(""); }} > setInput(event.target.value)} />

Status: {status}

); } ``` ```vue ``` ```svelte
{ if (!input.trim()) return; await chat.sendMessage({ input }); input = ""; }} >

Status: {$chat.status}

``` ```typescript import { useAgent } from "@better-agent/client/solid"; import { For, createSignal } from "solid-js"; import { client } from "./client"; export default function Page() { const { messages, status, sendMessage } = useAgent(client, { agent: "helloAgent", }); const [input, setInput] = createSignal(""); return (
{ event.preventDefault(); if (!input().trim()) return; await sendMessage({ input: input() }); setInput(""); }} > setInput(event.currentTarget.value)} />

Status: {status()}

); } ``` ```typescript import { useState } from "preact/hooks"; import { useAgent } from "@better-agent/client/preact"; import { client } from "./client"; export default function App() { const { messages, status, sendMessage } = useAgent(client, { agent: "helloAgent", }); ``` -------------------------------- ### Vue Component Setup with Better Agent Source: https://www.better-agent.com/docs/integrations/full-stack/nuxt Demonstrates the basic setup for a Vue.js component using Better Agent's `useAgent` hook. Ensure the client is correctly imported from '@better-agent/client/vue'. ```vue import { useAgent } from "@better-agent/client/vue"; import { client } from "~~/lib/better-agent/client"; const { agent } = useAgent(); ``` -------------------------------- ### Install Better Agent CLI with npm Source: https://www.better-agent.com/docs/get-started/installation Use this command to install the Better Agent CLI using npm. Ensure you have npm installed and configured. ```bash npm create better-agent ``` -------------------------------- ### Integrate and Start Fastify Server Source: https://www.better-agent.com/docs/integrations/backend/fastify Use toFastifyHandler to wrap the agent application and start the server on the specified port. ```typescript "/api/*", toFastifyHandler(agentApp)); await app.listen({ port: 3000 }); ``` -------------------------------- ### Install Better-Agent Core Packages Source: https://www.better-agent.com/docs/get-started/installation Use pnpm, yarn, or bun to add the core and provider packages for Better-Agent. ```bash pnpm add @better-agent/core @better-agent/providers ``` ```bash yarn add @better-agent/core @better-agent/providers ``` ```bash bun add @better-agent/core @better-agent/providers ``` -------------------------------- ### Initialize Better Agent Source: https://www.better-agent.com/docs/get-started/usage Basic setup for initializing a betterAgent instance with a model and system instructions. ```javascript const app = betterAgent({ agents: { text("gpt-5-mini"), instruction: "You are a friendly assistant. Keep answers short.", }); ``` -------------------------------- ### Initialize Better Agent in Vue Source: https://www.better-agent.com/docs/get-started/usage Setup the agent client within a Vue component using the setup script and TypeScript. ```typescript

Build a basic chat

In SvelteKit, use the Svelte adapter store. Read state through `$$chat` and call actions on `chat`.

``` -------------------------------- ### Install Better Agent Core Packages Source: https://www.better-agent.com/docs/get-started/installation Install the core Better Agent packages and the client package for typed frontends. This is required for building your agent application. ```bash npm install @better-agent/core @better-agent/providers ``` -------------------------------- ### Vue Setup with Better Agent Source: https://www.better-agent.com/docs/integrations/full-stack/nuxt This snippet demonstrates the initial setup for using the Better Agent client within a Vue.js application. It imports essential functions like `ref` and `useAgent`. ```typescript import { ref } from "vue"; import { useAgent } from "@better-agent/client/vue"; import { client } from "~~/lib/better-agent/client"; const input = ref( ``` -------------------------------- ### Create TypeScript Project Source: https://www.better-agent.com/docs/get-started/installation Initialize a new TypeScript project and configure the TypeScript compiler. Ensure you have Node.js and npm installed. ```bash mkdir my-agent && cd my-agent npm init -y npm install typescript -D npx tsc --init ``` -------------------------------- ### Initialize Better Agent Source: https://www.better-agent.com/docs/integrations/full-stack/tanstack-start Initializes the betterAgent application. This is a core setup step for using the library. ```javascript const app = betterAgent({ agents: [ assistant ], baseURL: "/agents", secret: "dev-secret", }); ``` -------------------------------- ### Initialize Agent with Client Source: https://www.better-agent.com/docs/integrations/full-stack/remix Initializes an agent using the provided client. This is a common setup for agents that interact with external services or APIs. ```javascript const agent = useAgent(client, { agent: "assistant", , initialMessages: [ { role: "assistant", parts: [{ type: "text", text: "Welcome back." }] }, ] }) ``` -------------------------------- ### Importing Hono server dependencies Source: https://www.better-agent.com/docs/integrations/backend/hono Initial setup for the Hono node server integration. ```typescript import { serve } from "@hono/node-server"; ``` -------------------------------- ### Initialize Logging Plugin Source: https://www.better-agent.com/llms-full.txt Basic setup for the logging plugin to track requests, events, and model calls. ```ts import { loggingPlugin } from "@better-agent/plugins"; const plugin = loggingPlugin(); ``` -------------------------------- ### Initialize a new project Source: https://www.better-agent.com/docs/get-started/installation Create a new directory and initialize the project using Bun. ```bash mkdir my-agent && cd my-agent bun init ``` -------------------------------- ### Billing Page Component (Vue.js) Source: https://www.better-agent.com/docs/integrations/full-stack/nuxt Example of a Vue.js component for a billing page, including script setup and import statements. ```vue ``` -------------------------------- ### Install Better Agent CLI with pnpm Source: https://www.better-agent.com/docs/get-started/installation Use this command to install the Better Agent CLI using pnpm. Ensure you have pnpm installed and configured. ```bash pnpm create better-agent ``` -------------------------------- ### Scaffold a new Better Agent project Source: https://www.better-agent.com/docs/get-started/installation Use the CLI to initialize a new project. Choose between npm, yarn, or bun package managers. ```bash yarn create better-agent ``` ```bash bun create better-agent ``` ```bash npm create better-agent ``` -------------------------------- ### Export GET Handler Constant Source: https://www.better-agent.com/docs/integrations/full-stack/nextjs Exports a constant named GET, likely representing a handler for GET requests. Ensure the 'handle' function is correctly defined elsewhere. ```javascript export const GET = handle; ``` -------------------------------- ### Run Agent Command Source: https://www.better-agent.com/docs/integrations/full-stack/sveltekit This snippet shows how to initiate a command to run an agent. It's a basic entry point for agent execution. ```bash $" Run" ``` -------------------------------- ### Initialize Agent with Context and Model Options Source: https://www.better-agent.com/llms-full.txt Use this to set up an agent with specific user context, plan, model parameters, and delivery method. ```tsx import { createFileRoute } from "@tanstack/react-router"; import { useAgent } from "@better-agent/client/react"; import { client } from "../better-agent/client"; export const Route = createFileRoute("/billing")({ component: BillingPage, }); function BillingPage() { const agent = useAgent(client, { agent: "assistant", context: { userId: "user_123", plan: "pro", }, modelOptions: { reasoningEffort: "medium", }, delivery: "stream", }); return ; } ``` -------------------------------- ### Initializing Agent with Observability Source: https://www.better-agent.com/docs/integrations/full-stack/tanstack-start This code demonstrates how to initialize the agent, passing the client and configuration options. It includes the use of the 'useAgent' hook. ```javascript useAgent(client, { agent: "assistant", onResponse: (response) => { console.log("HTTP status"); ``` -------------------------------- ### Initialize Better Agent Client Source: https://www.better-agent.com/docs/integrations/full-stack/nextjs Sets up the agent client with a specified role. This is the initial step to establish communication with the LLM. ```javascript import { useAgent } from "@/better-agent/client"; const { agent } = useAgent(client, { agent: "assistant", , toolHandlers: { toolHandlers: { show_confetti: async ({ color }) => { console.log(color) } } } }); ``` -------------------------------- ### Install Better Agent Dependencies Source: https://www.better-agent.com/docs/get-started/installation Command to install the core Better Agent packages using the Bun package manager. ```bash bun add @better-agent/core @better-agent/providers/openai ``` -------------------------------- ### Initialize TypeScript Project with pnpm Source: https://www.better-agent.com/llms-full.txt Manually set up a new TypeScript project using pnpm. This includes creating a directory, initializing pnpm, installing TypeScript, and initializing the TypeScript compiler. ```bash mkdir my-agent && cd my-agent pnpm init pnpm add typescript -D pnpm exec tsc --init ``` -------------------------------- ### Initialize TypeScript Project with yarn Source: https://www.better-agent.com/llms-full.txt Manually set up a new TypeScript project using yarn. This includes creating a directory, initializing yarn, installing TypeScript, and initializing the TypeScript compiler. ```bash mkdir my-agent && cd my-agent yarn init -y yarn add typescript -D yarn tsc --init ``` -------------------------------- ### Complex Message Structure Example Source: https://www.better-agent.com/docs/integrations/full-stack/tanstack-start An example demonstrating a more complex message structure, potentially for advanced use cases or specific formatting requirements. ```json { "type": "message", "role": "user", "content": "Hello!" } ``` -------------------------------- ### Import Express and Initialize App Source: https://www.better-agent.com/docs/integrations/backend/express This snippet shows how to import the Express library and create a new Express application instance. Ensure Express is installed in your project. ```javascript import agentApp from "./server"; const app = express(); ``` -------------------------------- ### Initialize Agent with Client Source: https://www.better-agent.com/docs/integrations/full-stack/remix Initializes an agent using a provided client. This is a foundational step for agent-based LLM interactions. ```javascript const agent = useAgent(client, { // ... }); ``` -------------------------------- ### Initialize xAI Provider with Better Agent Source: https://www.better-agent.com/llms-full.txt Set up the xAI provider and define an assistant agent. Ensure your XAI_API_KEY is set in the environment variables. ```typescript import { betterAgent, defineAgent } from "@better-agent/core"; import { createXAI } from "@better-agent/providers/xai"; const xai = createXAI({ apiKey: process.env.XAI_API_KEY, }); const assistant = defineAgent({ name: "assistant", model: xai.text("grok-4"), instruction: "You are a concise assistant. Keep replies short and natural.", }); const app = betterAgent({ agents: [assistant], }); ``` -------------------------------- ### Vue.js Script Setup for Agent Persistence Source: https://www.better-agent.com/docs/integrations/full-stack/nuxt This Vue.js script setup demonstrates how to configure a component for agent persistence. It includes importing necessary modules and setting up the script tag with TypeScript. ```vue