This project demonstrates how to build autonomous agents on Val Town that can be triggered by API calls, cron jobs, etc.
Remix this Val into your Val Town account.
Configure the following variables in your environment:
AGENT_API_KEY
(This is a secure token that you choose to secure the agent.tsx POST endpoint)OPENAI_API_KEY
(An OpenAI API Key)EXA_API_KEY
(Optional, though needed if you use the web search tool)
Use demo.tsx
to send objectives to your agent.
To use the API from another client, you can POST authenticated requests to the agent.tsx endpoint:
const requestBody = {
messages: [
{ role: "user", content: "What is the difference in height between the Salesforce Tower and the Empire State Building?" },
],
streamResults: false,
};
const response = await fetch("https://<your-val-id>.web.val.run/", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${Deno.env.get("AGENT_API_KEY")}`,
},
body: JSON.stringify(requestBody),
});
The API will also work with streaming chat front ends based on the Vercel AI SDK's useChat hook.
You just need to pass streamResults: true
in your API POST request.
It is easy to reconfigure the agent to work with other providers that are supported by Vercel's AI SDK, though not all models support tool calling.
Anthropic's models should work well, but the system prompt would need to be retuned to work with Claude.
Learn more: https://ai-sdk.dev/docs/foundations/providers-and-models