Ollama (Local)
.useLLM("ollama", "gemma3:12b").useLLM("ollama", "phi4-mini:latest").useLLM("ollama", "llama3.2:latest")
Get up and running with AgentForce ADK in just a few minutes. This guide will walk you through creating your first AI agent.
Let’s create a simple conversational agent:
import { AgentForceAgent } from '@agentforce/adk';
// Create agent configuration const agentConfig = { name: "MyFirstAgent" };
// Create and configure your agent const agent = new AgentForceAgent(agentConfig) .useLLM("ollama", "gemma3:12b") .systemPrompt("You are a helpful AI assistant specialized in TypeScript development") .prompt("Hello! Can you help me understand TypeScript interfaces?");
// Generate response const textResponse = await agent.output("text"); console.log("Agent Response:", textResponse);
Run your agent:
bun run my-first-agent.ts
# For TypeScriptnpx tsx my-first-agent.ts
# For JavaScript with jsrnode my-first-agent.js
deno run --allow-net my-first-agent.ts
Let’s break down what’s happening:
const agentConfig = { name: "MyFirstAgent"};
Every agent needs a name for identification and logging.
Learn more about Agent Configuration.
const agent = new AgentForceAgent(agentConfig) .useLLM("ollama", "gemma3:12b") .systemPrompt("You are a helpful AI assistant") .prompt("Hello! Tell me a joke")
AgentForce ADK uses method chaining for intuitive configuration:
.useLLM()
- Configure the AI provider and model.systemPrompt()
- Set the system instructions.prompt()
- Set the user inputAll Agent Methods are documented in the Agent Reference.
const response = await agent.output("text"); // Get formatted output
const agent = new AgentForceAgent(config) .useLLM("ollama", "gemma3:12b") .systemPrompt("You are a helpful assistant") .prompt("Explain quantum computing in simple terms");
const textResponse = await await agent.output("text");console.log(textResponse);
const agent = new AgentForceAgent(config) .useLLM("ollama", "gemma3:12b") .systemPrompt("You are a data analyst. Respond in JSON format") .prompt("Analyze this data: [1,2,3,4,5]");
const jsonResponse = await agent.output("json");console.log(JSON.parse(jsonResponse));
const agent = new AgentForceAgent(config) .useLLM("ollama", "gemma3:12b") .systemPrompt("You are a technical writer") .prompt("Write a brief guide about REST APIs");
const markdownResponse = await agent.output("md");console.log(markdownResponse);
Ollama (Local)
.useLLM("ollama", "gemma3:12b").useLLM("ollama", "phi4-mini:latest").useLLM("ollama", "llama3.2:latest")
OpenRouter (Cloud)
.useLLM("openrouter", "openai/gpt-4").useLLM("openrouter", "anthropic/claude-3-sonnet").useLLM("openrouter", "meta-llama/llama-3.1-8b-instruct")
Here’s a more comprehensive example that creates a story generator agent:
import { AgentForceAgent } from '@agentforce/adk';
async function createStoryGenerator() { const storyAgent = new AgentForceAgent({ name: "StoryGenerator" }) .useLLM("ollama", "gemma3:12b") .systemPrompt(` You are a creative writing assistant. Create engaging short stories with: - Compelling characters - Clear plot structure - Vivid descriptions - Satisfying conclusions
Keep stories under 500 words. `) .prompt("Write a short story about a robot who learns to paint");
// Get different output formats const story = await storyAgent.getResponse(); console.log("Generated Story:\n", story);
return story;}
// Run the story generatorcreateStoryGenerator().catch(console.error);
Always include proper error handling in your agents:
import { AgentForceAgent } from '@agentforce/adk';
async function robustAgent() { try { const agent = new AgentForceAgent({ name: "RobustAgent" }) .useLLM("ollama", "gemma3:12b") .systemPrompt("You are a helpful assistant") .prompt("Hello world!");
const response = await agent.output("text"); return response;
} catch (error) { console.error("Agent execution failed:", error); return "Sorry, I encountered an error. Please try again."; }}
// Run the robust agentrobustAgent().then(response => { console.log("Agent Response:", response);});
Now that AgentForce ADK is installed, you’ll need to set up AI providers to power your agents:
Congratulations! You’ve successfully created your first AgentForce ADK agent. The framework’s method chaining approach makes it easy to build powerful AI-powered applications with minimal code.