{"repo": "ahmadexe/agenix", "files": {"README.md": {"76ff19e9b94fb52c98d821071642fb2fea3bce84": {"t": 1785746475.3573189, "n": 24196, "h": "81943c40e7f458e8", "c": "\n\n# Agenix\n\n
\n\nA Flutter package for building AI agents with memory, tools, and multi-agent orchestration. Define your agent's personality, give it tools, and let it handle conversations — including delegating sub-tasks across a chain of specialized agents.\n\n\n\n---\n\n## Packages\n\nThis is a monorepo containing the following packages:\n\n| Package | pub.dev | Description |\n|---|---|---|\n| [`agenix`](packages/agenix/) | [](https://pub.dev/packages/agenix) | Core — agents, tools, LLM interface, in-memory data store |\n| [`agenix_firebase`](packages/agenix_firebase/) | [](https://pub.dev/packages/agenix_firebase) | Firebase (Firestore + Storage + Auth) data store backend |\n\n### Choosing a data store\n\nThe core `agenix` package ships with `DataStore.inMemory()` — a zero-dependency store for testing and prototyping. For production persistence, add a backend package:\n\n```yaml\n# Core only (no Firebase):\ndependencies:\n agenix: ^4.1.2\n\n# With Firebase persistence:\ndependencies:\n agenix: ^4.1.2\n agenix_firebase: ^1.0.4\n```\n\n```dart\nimport 'package:agenix/agenix.dart';\n\n// In-memory (no extra package needed):\nfinal store = DataStore.inMemory();\n\n// Firebase (requires agenix_firebase):\nimport 'package:agenix_firebase/agenix_firebase.dart';\nfinal store = FirebaseDataStore();\n```\n\nThis separation means apps that don't use Firebase never pull in the Firebase SDK.\n\n> **Migrating from agenix 3.x?** Replace `DataStore.firestoreDataStore()` with `FirebaseDataStore()` and add `agenix_firebase` to your pubspec. See the [core CHANGELOG](packages/agenix/CHANGELOG.md) for details.\n\n---\n\n## Table of Contents\n\n- [Architecture Overview](#architecture-overview)\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n- [Core Concepts](#core-concepts)\n - [Agent](#agent)\n - [LLM](#llm)\n - [DataStore (Memory)](#datastore-memory)\n - [Tools](#tools)\n - [Multi-Agent Orchestration](#multi-agent-orchestration)\n - [Agent Scopes](#agent-scopes)\n- [Error Handling](#error-handling)\n- [API Reference](#api-reference)\n- [Usage Architectures](#usage-architectures)\n- [Examples](#examples)\n- [Maintainers](#maintainers)\n\n---\n\n## Architecture Overview\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│ Your Flutter App │\n│ │\n│ Agent.create(llm, dataStore, name, role) │\n│ │ │\n│ ▼ │\n│ ┌─────────┐ generateResponse() ┌───────────────┐ │\n│ │ Agent │ ◄─────────────────────► │ LLM │ │\n│ │ │ │ (Gemini/OpenAI│ │\n│ │ │ │ Groq/Anthropic│ │\n│ │ │ │ + Custom) │ │\n│ └────┬────┘ └───────────────┘ │\n│ │ │\n│ ┌────┴──────────────────────────┐ │\n│ │ │ │ │\n│ ▼ ▼ ▼ │\n│ ┌──────┐ ┌──────────┐ ┌────────────────┐ │\n│ │Tools │ │DataStore │ │Agent Registry │ │\n│ │ │ │(InMemory/ │ │(Multi-Agent │ │\n│ │ │ │ Firebase/ │ │ Orchestration) │ │\n│ │ │ │ Custom) │ │ │ │\n│ └──────┘ └──────────┘ └────────────────┘ │\n└─────────────────────────────────────────────────────────────┘\n```\n\nThe agent receives a user message, builds a structured prompt (including conversation history from the DataStore and available tools from the ToolRegistry), sends it to the LLM, and parses the response into one of three actions:\n\n1. **Direct response** — returns text to the user\n2. **Tool invocation** — runs one or more tools, optionally iterating up to 5 times before producing a final answer\n3. **Agent delegation** — hands the task to a chain of other agents, each passing its output to the next\n\n---\n\n## Installation\n\nAdd to your `pubspec.yaml`:\n\n```yaml\ndependencies:\n agenix: ^4.1.2\n```\n\nIf you need Firebase persistence, also add:\n\n```yaml\n agenix_firebase: ^1.0.4\n```\n\nThen run:\n\n```bash\nflutter pub get\n```\n\n---\n\n## Quick Start\n\n### 1. Create system data\n\nCreate `assets/system_data.json` with your agent's personality and background knowledge:\n\n```json\n{\n \"name\": \"Lens\",\n \"role\": \"A helpful assistant for the Acme platform\",\n \"personality\": \"Friendly, concise, and knowledgeable\",\n \"instructions\": \"Always greet the user by name when possible\"\n}\n```\n\nAdd the asset to your `pubspec.yaml`:\n\n```yaml\nflutter:\n assets:\n - assets/system_data.json\n```\n\n### 2. Initialize the agent\n\n```dart\nimport 'package:agenix/agenix.dart';\n\nfinal agent = await Agent.create(\n dataStore: DataStore.inMemory(),\n llm: LLM.geminiLLM(\n apiKey: 'YOUR_API_KEY',\n modelName: 'gemini-2.0-flash',\n ),\n name: 'Assistant',\n role: 'General purpose assistant for the platform.',\n);\n```\n\nFor Firebase persistence:\n\n```dart\nimport 'package:agenix_firebase/agenix_firebase.dart';\n\nfinal agent = await Agent.create(\n dataStore: FirebaseDataStore(),\n llm: LLM.geminiLLM(apiKey: 'YOUR_API_KEY', modelName: 'gemini-2.0-flash'),\n name: 'Assistant',\n role: 'General purpose assistant for the platform.',\n);\n```\n\n### 3. Generate a response\n\n```dart\nfinal response = await agent.generateResponse(\n convoId: 'conversation-1',\n userMessage: AgentMessage(\n content: 'What is the weather like today?',\n isFromAgent: false,\n generatedAt: DateTime.now(),\n ),\n);\n\nprint(response.content);\n```\n\n### 4. Run the app\n\n```bash\nflutter run -d chrome --dart-define=GEMINI_API_KEY=your-key-here\n```\n\n---\n\n## Core Concepts\n\n### Agent\n\nThe `Agent` is the central class. It wires together an LLM, a DataStore, a ToolRegistry, and an AgentScope.\n\n```dart\nfinal agent = await Agent.create(\n dataStore: DataStore.inMemory(),\n llm: LLM.geminiLLM(apiKey: key, modelName: 'gemini-2.0-flash'),\n name: 'Support Agent',\n role: 'Handles customer support queries for the e-commerce platform.',\n failureMode: FailureMode.throwError, // or FailureMode.gracefulMessage (default)\n onError: (error, stack) => logger.severe('Agent error', error, stack),\n scope: AgentScope.global, // default — or create isolated scopes\n registrationPolicy: RegistrationPolicy.throwIfExists, // default\n);\n```\n\n**Key methods:**\n\n| Method | Description |\n|---|---|\n| `generateResponse(convoId, userMessage)` | Send a user message and get back an `AgentMessage` from the agent |\n| `getMessages(conversationId)` | Retrieve all messages in a conversation |\n| `getAllConversations()` | List all conversations for the current user |\n| `deleteConversation(conversationId)` | Delete a conversation and its messages |\n| `dispose()` | Unregister the agent from its scope |\n\n**Parameters for `generateResponse`:**\n\n| Parameter | Type | Default | Description |\n|---|---|---|---|\n| `convoId` | `String` | required | Conversation identifier |\n| `userMessage` | `AgentMessage` | required | The user's message |\n| `memoryLimit` | `int` | `10` | Max previous messages loaded as context |\n| `metaData` | `Object?` | `null` | Opaque pass-through for auth tokens, tenant IDs, etc. |\n\n---\n\n### LLM\n\nThe `LLM` abstract class defines the contract for language model providers. Agenix ships with built-in adapters for the most popular providers — pick one or implement your own.\n\n| Factory | Provider | Example model |\n|---|---|---|\n| `LLM.geminiLLM()` | Google Gemini | `gemini-2.0-flash` |\n| `LLM.openAiLLM()` | OpenAI | `gpt-4o` |\n| `LLM.anthropicLLM()` | Anthropic (Claude) | `claude-sonnet-4-5` |\n| `LLM.groqLLM()` | Groq | `llama-3.3-70b-versatile` |\n| `LLM.mistralLLM()` | Mistral AI | `mistral-large-latest` |\n| `LLM.deepseekLLM()` | DeepSeek | `deepseek-chat` |\n| `LLM.grokLLM()` | xAI (Grok) | `grok-4` |\n| `LLM.cohereLLM()` | Cohere | `command-r-plus-08-2024` |\n\n```dart\n// Google Gemini\nfinal llm = LLM.geminiLLM(\n apiKey: 'YOUR_API_KEY',\n modelName: 'gemini-2.0-flash',\n config: LlmConfig(\n temperature: 0.2,\n maxOutputTokens: 2048,\n jsonMode: true,\n timeout: Duration(seconds: 60),\n ),\n);\n\n// OpenAI\nfinal llm = LLM.openAiLLM(apiKey: 'YOUR_API_KEY', modelName: 'gpt-4o');\n\n// Anthropic (Claude)\nfinal llm = LLM.anthropicLLM(apiKey: 'YOUR_API_KEY', modelName: 'claude-sonnet-4-5');\n\n// Groq — fast inference, free tier available\nfinal llm = LLM.groqLLM(apiKey: 'YOUR_API_KEY', modelName: 'llama-3.3-70b-versatile');\n\n// Mistral\nfinal llm = LLM.mistralLLM(apiKey: 'YOUR_API_KEY', modelName: 'mistral-large-latest');\n\n// DeepSeek\nfinal llm = LLM.deepseekLLM(apiKey: 'YOUR_API_KEY', modelName: 'deepseek-chat');\n\n// xAI (Grok)\nfinal llm = LLM.grokLLM(apiKey: 'YOUR_API_KEY', modelName: 'grok-4');\n\n// Cohere\nfinal llm = LLM.cohereLLM(apiKey: 'YOUR_API_KEY', modelName: 'command-r-plus-08-2024');\n```\n\n**Implementing a custom LLM** (e.g. your own backend):\n\n```dart\nclass MyCustomLLM implements LLM {\n @override\n final String modelId = 'my-model-v1';\n\n @override\n final LlmConfig config;\n\n MyCustomLLM({this.config = const LlmConfig()});\n\n @override\n Future