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.
Learn more: https://ai-sdk.dev/docs/foundations/providers-and-models
Are you a Senior Software Engineer who wants to work on AI or TypeScript? Feel free to DM me on the Val Town Discord to learn more about careers at AngelList. We're solving some of the hardest problems in Venture Capital and Private Markets and are always looking for great people to join us.