01 · Hello World 🟢
The absolute simplest agent. No tools. No memory. Just a conversation.
What you'll learn
- How to install confused-ai
- How to create an agent
- How to send a message and get a reply
Setup
bash
npm install confused-aiCreate a .env file:
bash
OPENAI_API_KEY=sk-...Code
ts
// hello-world.ts
import { createAgent } from 'confused-ai';
// 1. Create the agent
const agent = createAgent({
name: 'hello-agent',
model: 'gpt-4o-mini', // cheap + fast, great for dev
instructions: `
You are a friendly assistant.
Answer clearly and concisely.
`,
});
// 2. Send a message
const result = await agent.run('What is the capital of France?');
// 3. Read the reply
console.log(result.text);
// → "The capital of France is Paris."Run it
bash
npx tsx hello-world.tsWhat happened?
createAgent()sets up the agent with a model and instructions.run()sends your message to the model and waits for the replyresult.textis the plain-text response
Try changing it
- Swap
'gpt-4o-mini'for'claude-3-haiku-20240307'if you have an Anthropic key - Change the
instructionsto make the agent answer only in French - Ask a follow-up question by calling
.run()again with a different message
What's next?
- 02 · First Custom Tool — give your agent real-world abilities