Production-ready SDK for building AI agents with MCP tools
Quick Start β’ Features β’ Examples β’ Architecture β’ Documentation
FlowLLM is a production-ready SDK that makes building AI agents with Model Context Protocol (MCP) tools ridiculously easy.
Unlike existing frameworks that are either too low-level, too opinionated, or missing MCP support, FlowLLM gives you:
- β Model-agnostic by default (OpenAI, Anthropic, Gemini, local models)
- β MCP-native integration (use any MCP server as agent tools)
- β Production primitives (streaming, retries, error handling, cost tracking)
- β Deploy anywhere (works with any Node.js hosting platform)
import { defineAgent, openai } from '@targetly-labs/flowllm';
const agent = defineAgent({
provider: openai('gpt-4o'),
systemPrompt: 'You are a helpful assistant.',
});
const response = await agent.execute('What is the capital of France?');
console.log(response.content);npm install @targetly-labs/flowllmimport { defineAgent, openai } from '@targetly-labs/flowllm';
// 1. Define your agent
const agent = defineAgent({
provider: openai('gpt-4o'),
systemPrompt: 'You are a helpful assistant.',
temperature: 0.7,
});
// 2. Execute a single query
const response = await agent.execute('Tell me a joke');
console.log(response.content);
// 3. Or stream responses
const stream = await agent.stream('Write a poem about TypeScript');
for await (const chunk of stream) {
process.stdout.write(chunk.content || '');
}import { openai, anthropic, gemini } from '@targetly-labs/flowllm/providers';
// OpenAI
const gptAgent = defineAgent({
provider: openai('gpt-4o'),
systemPrompt: 'You are a helpful assistant.',
});
// Anthropic
const claudeAgent = defineAgent({
provider: anthropic('claude-3-5-sonnet-20240620'),
systemPrompt: 'You are a helpful assistant.',
});
// Google Gemini
const geminiAgent = defineAgent({
provider: gemini('gemini-pro'),
systemPrompt: 'You are a helpful assistant.',
});- Goal-driven agent execution
- Multi-turn conversations with memory
- Tool selection and orchestration
- Streaming responses
- Single API for multiple providers (OpenAI, Anthropic, Gemini)
- Automatic retries and error handling
- Built-in cost tracking
- Token counting and management
- Native MCP protocol support
- Automatic tool discovery from MCP servers
- Type-safe tool calls
- Works with any MCP server
- Short-term conversation memory
- Token window management
- Custom memory strategies
- Context persistence
- Token-by-token streaming
- Server-sent events support
- Progress updates
- UI-friendly streaming APIs
- Type-safe tool definitions
- Schema validation with Zod
- Retry and fallback handling
- Custom function support
- Automatic retry logic for transient errors
- Cost and token tracking (per request/session)
- Request/response middleware
- Structured logging with Pino
- Performance monitoring
import { defineAgent, openai } from '@targetly-labs/flowllm';
const agent = defineAgent({
provider: openai('gpt-4o'),
systemPrompt: 'You are a helpful coding assistant.',
});
const response = await agent.execute('How do I reverse a string in JavaScript?');
console.log(response.content);const agent = defineAgent({
provider: openai('gpt-4o'),
systemPrompt: 'You are a creative writer.',
});
const stream = await agent.stream('Write a short story about a robot');
for await (const chunk of stream) {
process.stdout.write(chunk.content || '');
}import { defineAgent, defineTool, openai } from '@targetly-labs/flowllm';
const weatherTool = defineTool({
name: 'get_weather',
description: 'Get current weather for a location',
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'City name',
},
},
required: ['location'],
},
execute: async ({ location }) => {
// Your weather API logic here
return { temp: 72, condition: 'sunny', location };
},
});
const agent = defineAgent({
provider: openai('gpt-4o'),
tools: [weatherTool],
systemPrompt: 'You are a helpful weather assistant.',
});
const response = await agent.execute('What\'s the weather in Tokyo?');
console.log(response.content);import { defineAgent, openai, anthropic } from '@targetly-labs/flowllm';
// Create agents with different providers
const agents = {
gpt: defineAgent({
provider: openai('gpt-4o'),
systemPrompt: 'You are GPT-4.',
}),
claude: defineAgent({
provider: anthropic('claude-3-5-sonnet-20240620'),
systemPrompt: 'You are Claude.',
}),
};
// Use the right agent for the job
const technicalResponse = await agents.claude.execute('Explain async/await');
const creativeResponse = await agents.gpt.execute('Write a haiku');FlowLLM uses a layered architecture for maximum flexibility and maintainability:
βββββββββββββββββββββββββββββββββββββββββββββββ
β FlowLLM SDK β
β βββββββββββββββββββββββββββββββββββββββ β
β β Agent Framework β β
β β - Conversation management β β
β β - Tool orchestration β β
β β - Memory handling β β
β βββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β LLM β β MCP β β Tools β β
β β Client β βConnector β β System β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
ββββββ¬βββββββββββββββ¬βββββββββββββββ¬ββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββ ββββββββββββββ ββββββββββββ
β OpenAI β β MCP Server β β Custom β
βAnthropicβ β (Future) β β Function β
β Gemini β β β β Tools β
βββββββββββ ββββββββββββββ ββββββββββββ
- Agent: Orchestrates conversation flow, memory, and tool execution
- LLMClient: Unified interface for all LLM providers
- ToolRegistry: Manages and executes custom tools and MCP tools
- Memory: Handles conversation history and token management
- CostTracker: Tracks token usage and costs across requests
- RetryHandler: Implements exponential backoff for transient errors
For detailed architecture diagrams and data flows, see ARCHITECTURE.md.
Build AI features into your product with ease.
const supportAgent = defineAgent({
provider: openai('gpt-4o'),
systemPrompt: 'Help customers with their support tickets.',
});Build agents that can take actions and make decisions.
const codeReviewAgent = defineAgent({
provider: anthropic('claude-3-5-sonnet-20240620'),
systemPrompt: 'Review code and suggest improvements.',
});Build chatbots, Discord bots, Slack bots with LLM capabilities.
const discordBot = defineAgent({
provider: gemini('gemini-pro'),
systemPrompt: 'Helpful Discord bot.',
});Build internal AI assistants for your team.
const opsAgent = defineAgent({
provider: openai('gpt-4o'),
systemPrompt: 'Help with DevOps tasks and incident response.',
});- π Getting Started - Complete setup guide
- ποΈ Architecture - Technical architecture details
- π Implementation Guide - Advanced patterns
- π Security - Security best practices
- π€ Contributing - Contribution guidelines
- π Changelog - Version history
- Core agent framework
- Multi-provider LLM client (OpenAI, Anthropic, Gemini)
- Conversation memory
- Custom tool calling
- Streaming responses
- Error handling & retries
- Cost tracking
- TypeScript support
- Native MCP protocol support
- Automatic tool discovery
- Type-safe MCP tool calls
- MCP server integration examples
- Advanced memory systems (long-term, user profiles)
- Multi-agent orchestration
- Prompt versioning
- Execution tracing and analytics
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
# Clone the repository
git clone https://github.com/targetly-labs/flowllm.git
# Install dependencies
cd flowllm
npm install
# Run tests
npm test
# Build the project
npm run buildMIT License - See LICENSE for details
If you find FlowLLM useful, please consider:
- β Starring the repository
- π Reporting bugs and issues
- π‘ Suggesting new features
- π€ Contributing code
- π’ Sharing with others
- NPM Package: @targetly-labs/flowllm
- GitHub: targetly-labs/flowllm
- Issues: Report a bug
- Documentation: Full Docs
Built with β€οΈ by the Targetly Labs team