### Start AgentBridge Daemon Source: https://github.com/feiyun0112/agentbridge/blob/main/README.md Initializes the AgentBridge daemon for the specified provider. ```bash # Start (runs as background daemon; auto-login if no account saved) agent-bridge start --provider weixin ``` -------------------------------- ### Start AgentBridge Service Source: https://github.com/feiyun0112/agentbridge/blob/main/README_zh-CN.md Initializes the bridge service using the specified provider. ```bash agent-bridge start --provider weixin ``` -------------------------------- ### AgentBridge Configuration File Source: https://github.com/feiyun0112/agentbridge/blob/main/README_zh-CN.md Example of the JSON configuration file located at ~/.agent-bridge/config.json. ```json { "default_agent": "claude", "agents": { "claude": { "type": "acp", "command": "/usr/local/bin/claude-agent-acp", "model": "sonnet" }, "codex": { "type": "cli", "command": "/usr/local/bin/copilot" } } } ``` -------------------------------- ### Override Configuration with Environment Variables Source: https://context7.com/feiyun0112/agentbridge/llms.txt Use environment variables to override default settings before starting the bridge. ```bash # Override the default agent export AGENT_BRIDGE_DEFAULT_AGENT=codex # Override the HTTP API listen address export AGENT_BRIDGE_API_ADDR=0.0.0.0:9090 # OpenClaw gateway configuration export OPENCLAW_GATEWAY_URL=ws://127.0.0.1:8765 export OPENCLAW_GATEWAY_TOKEN=your-token-here export OPENCLAW_GATEWAY_PASSWORD=your-password-here # Start the bridge with environment overrides agent-bridge start --provider weixin ``` -------------------------------- ### Manage AgentBridge Daemon via CLI Source: https://context7.com/feiyun0112/agentbridge/llms.txt Commands to start, stop, and monitor the AgentBridge daemon process. ```bash # Start the bridge as a background daemon (default behavior) # Auto-detects installed agents and prompts for WeChat login if needed agent-bridge start --provider weixin # Start in foreground mode for debugging agent-bridge start --provider weixin --foreground # Start with custom API address and skip permission prompts agent-bridge start --provider weixin --api-addr 0.0.0.0:8080 --dangerously-skip-permissions # Add a WeChat account via QR code scan agent-bridge login --provider weixin # Check daemon status agent-bridge status --provider weixin # Stop the background daemon agent-bridge stop --provider weixin # Restart the daemon agent-bridge restart --provider weixin ``` -------------------------------- ### GET /health Source: https://context7.com/feiyun0112/agentbridge/llms.txt Performs a health check on the AgentBridge service to ensure it is operational. ```APIDOC ## GET /health ### Description Checks the status of the AgentBridge service. ### Method GET ### Endpoint /health ### Response #### Success Response (200) - **status** (string) - Returns "ok" if the service is healthy. ``` -------------------------------- ### Build and Run from Source Source: https://github.com/feiyun0112/agentbridge/blob/main/README_zh-CN.md Commands for building and running the project using the .NET 8 SDK. ```bash # 还原依赖并构建 dotnet build AgentBridge.slnx # 直接运行 dotnet run --project src/AgentBridge.CLI --framework net8.0 -- start --provider weixin # 发布独立可执行文件(Windows 示例) dotnet publish src/AgentBridge.CLI -c Release -r win-x64 --self-contained ``` -------------------------------- ### Build and Run from Source Source: https://github.com/feiyun0112/agentbridge/blob/main/README.md Commands to restore, build, and publish the AgentBridge project using the .NET 8 SDK. ```bash # Restore & build dotnet build AgentBridge.slnx # Run directly dotnet run --project src/AgentBridge.CLI --framework net8.0 -- start --provider weixin # Publish self-contained binary (Windows example) dotnet publish src/AgentBridge.CLI -c Release -r win-x64 --self-contained ``` -------------------------------- ### Configure and use CliAgent Source: https://context7.com/feiyun0112/agentbridge/llms.txt Spawns a new process for each message, supporting session resumption via the --resume flag. ```csharp using AgentBridge.Core.Agent; using Microsoft.Extensions.Logging; // Configure a CLI agent for Claude var claudeConfig = new CliAgentConfig { Name = "claude", Command = "/usr/local/bin/claude", Args = Array.Empty(), Cwd = "/home/user/workspace", Model = "sonnet", SystemPrompt = "Be concise in your responses.", AllowAll = true // Pass --dangerously-skip-permissions }; var logger = LoggerFactory.Create(b => b.AddConsole()).CreateLogger("CLI"); var claudeAgent = new CliAgent(claudeConfig, logger); // Each call spawns a new process; sessions are tracked internally string response = await claudeAgent.ChatAsync("user-123", "Write a hello world in Rust"); Console.WriteLine(response); // Subsequent calls to same conversationId use --resume with saved session string followUp = await claudeAgent.ChatAsync("user-123", "Now add error handling"); Console.WriteLine(followUp); // Configure a CLI agent for Copilot var copilotConfig = new CliAgentConfig { Name = "copilot", Command = "/usr/local/bin/copilot", AllowAll = true // Passes --yolo flag to copilot }; var copilotAgent = new CliAgent(copilotConfig, logger); string copilotResponse = await copilotAgent.ChatAsync("user-789", "Refactor this function"); Console.WriteLine(copilotResponse); ``` -------------------------------- ### Build and Run AgentBridge via CLI Source: https://context7.com/feiyun0112/agentbridge/llms.txt Commands for cloning, building, running, and publishing the AgentBridge project. Requires .NET 8 SDK or later. ```bash # Prerequisites: .NET 8 SDK or later # https://dotnet.microsoft.com/download # Clone and build git clone https://github.com/example/agent-bridge.git cd agent-bridge dotnet build AgentBridge.slnx # Run directly in foreground mode dotnet run --project src/AgentBridge.CLI --framework net8.0 -- \ start --provider weixin --foreground # Run with custom API address dotnet run --project src/AgentBridge.CLI --framework net8.0 -- \ start --provider weixin -f --api-addr 0.0.0.0:9090 # Publish self-contained binary for different platforms # Windows x64 dotnet publish src/AgentBridge.CLI -c Release -r win-x64 --self-contained # Linux x64 dotnet publish src/AgentBridge.CLI -c Release -r linux-x64 --self-contained # macOS ARM64 dotnet publish src/AgentBridge.CLI -c Release -r osx-arm64 --self-contained # The published binary can be run without .NET runtime installed ./publish/agent-bridge start --provider weixin ``` -------------------------------- ### Create agents with AgentBuilder Source: https://context7.com/feiyun0112/agentbridge/llms.txt Factory utility for auto-detecting and instantiating agents based on configuration files. ```csharp using AgentBridge.Core.Agent; using AgentBridge.Core.Config; using Microsoft.Extensions.Logging; // Load configuration AppConfig cfg = ConfigManager.Load(); // Auto-detect and configure available agents var loggerFactory = LoggerFactory.Create(b => b.AddConsole()); var logger = loggerFactory.CreateLogger("Setup"); if (AgentDetector.DetectAndConfigure(cfg, logger)) { ConfigManager.Save(cfg); Console.WriteLine($"Detected agents: {string.Join(", ", cfg.Agents.Keys)}"); } // Create an agent by name from config IAgent? claude = AgentBuilder.Create(cfg, "claude", loggerFactory, allowAll: true); if (claude != null) { string response = await claude.ChatAsync("conv-1", "Explain monads"); Console.WriteLine(response); } // Create with YOLO mode disabled (will prompt for permissions) IAgent? codex = AgentBuilder.Create(cfg, "codex", loggerFactory, allowAll: false); if (codex != null) { string response = await codex.ChatAsync("conv-2", "Create a REST API"); Console.WriteLine(response); } // Handle missing agents gracefully IAgent? missing = AgentBuilder.Create(cfg, "nonexistent", loggerFactory); if (missing == null) { Console.WriteLine("Agent not found in configuration"); } ``` -------------------------------- ### CLI Command Syntax Source: https://github.com/feiyun0112/agentbridge/blob/main/README_zh-CN.md General structure for executing CLI commands. ```bash agent-bridge <命令> --provider <提供方> [选项] ``` -------------------------------- ### Initialize MessageHandler in C# Source: https://context7.com/feiyun0112/agentbridge/llms.txt Configures the MessageHandler with agent factories and default agent persistence. Requires the AgentBridge.Core and AgentBridge.Weixin namespaces. ```csharp using AgentBridge.Core.Agent; using AgentBridge.Core.Config; using AgentBridge.Weixin.Messaging; using Microsoft.Extensions.Logging; var loggerFactory = LoggerFactory.Create(b => b.AddConsole()); var cfg = ConfigManager.Load(); // Create the message handler with agent factory and save callback var handler = new MessageHandler( factory: name => AgentBuilder.Create(cfg, name, loggerFactory, allowAll: true), saveDefault: name => { cfg.DefaultAgent = name; ConfigManager.Save(cfg); }, logger: loggerFactory.CreateLogger() ); // Set available agent metadata for status display handler.SetAgentMetas(cfg.Agents .Select(kv => new AgentMeta { Name = kv.Key, Type = kv.Value.Type, Command = kv.Value.Command ?? "", Model = kv.Value.Model ?? "" }) .ToList()); // Initialize and set the default agent IAgent? defaultAgent = AgentBuilder.Create(cfg, cfg.DefaultAgent, loggerFactory, allowAll: true); if (defaultAgent != null) { handler.SetDefaultAgent(cfg.DefaultAgent, defaultAgent); } ``` -------------------------------- ### CLI Command Syntax Source: https://github.com/feiyun0112/agentbridge/blob/main/README.md General syntax for executing AgentBridge CLI commands. ```bash agent-bridge --provider [options] ``` -------------------------------- ### Manage Application Configuration with ConfigManager Source: https://context7.com/feiyun0112/agentbridge/llms.txt Use ConfigManager to load, modify, and save application settings. Environment variables can override configuration values during loading. Ensure the config file path is correctly set. ```csharp using AgentBridge.Core.Config; // Get the config file path (~/.agent-bridge/config.json) string configPath = ConfigManager.ConfigPath(); Console.WriteLine($"Config location: {configPath}"); // Load configuration (creates default if missing) AppConfig cfg = ConfigManager.Load(); // Access current settings Console.WriteLine($"Default agent: {cfg.DefaultAgent}"); Console.WriteLine($"API address: {cfg.ApiAddr}"); Console.WriteLine($"Configured agents: {string.Join(", ", cfg.Agents.Keys)}"); // Modify configuration cfg.DefaultAgent = "codex"; cfg.ApiAddr = "0.0.0.0:9090"; // Add a new agent configuration cfg.Agents["custom"] = new AgentConfig { Type = "acp", Command = "/usr/local/bin/custom-agent", Model = "gpt-4", Cwd = "/home/user/projects" }; // Save changes (atomic write via temp file) ConfigManager.Save(cfg); // Environment variables automatically override on Load() // AGENT_BRIDGE_DEFAULT_AGENT overrides cfg.DefaultAgent // AGENT_BRIDGE_API_ADDR overrides cfg.ApiAddr ``` -------------------------------- ### Configure AgentBridge Settings Source: https://context7.com/feiyun0112/agentbridge/llms.txt The configuration file located at ~/.agent-bridge/config.json defines agent types, commands, and API settings. ```json { "default_agent": "claude", "api_addr": "127.0.0.1:18088", "agents": { "claude": { "type": "acp", "command": "/usr/local/bin/claude-agent-acp", "model": "sonnet", "system_prompt": "You are a helpful coding assistant.", "cwd": "/home/user/projects" }, "codex": { "type": "cli", "command": "/usr/local/bin/codex", "args": ["--model", "gpt-4"] }, "cursor": { "type": "acp", "command": "/usr/local/bin/agent", "args": ["acp"] }, "copilot": { "type": "cli", "command": "/usr/local/bin/copilot" } } } ``` -------------------------------- ### Configure and use AcpAgent Source: https://context7.com/feiyun0112/agentbridge/llms.txt Initializes a long-lived JSON-RPC agent process and manages conversation sessions via conversation IDs. ```csharp using AgentBridge.Core.Agent; using Microsoft.Extensions.Logging; // Configure an ACP agent var config = new AcpAgentConfig { Command = "/usr/local/bin/claude-agent-acp", Args = Array.Empty(), Cwd = "/home/user/workspace", Model = "sonnet", SystemPrompt = "You are a helpful coding assistant.", AllowAll = true // Skip permission prompts }; var logger = LoggerFactory.Create(b => b.AddConsole()).CreateLogger("ACP"); await using var agent = new AcpAgent(config, logger); // Start the agent subprocess and initialize JSON-RPC handshake await agent.StartAsync(); // Chat with the agent - sessions are automatically managed per conversationId string response1 = await agent.ChatAsync("user-123", "What is dependency injection?"); Console.WriteLine(response1); // Subsequent messages reuse the same session string response2 = await agent.ChatAsync("user-123", "Can you show me an example in C#?"); Console.WriteLine(response2); // Different conversationId creates a new session string response3 = await agent.ChatAsync("user-456", "Explain SOLID principles"); Console.WriteLine(response3); // Get agent info var info = agent.Info(); Console.WriteLine($"Agent: {info.Name}, Type: {info.Type}, Model: {info.Model}, PID: {info.Pid}"); ``` -------------------------------- ### Auto-Discover Agents with AgentDetector Source: https://context7.com/feiyun0112/agentbridge/llms.txt AgentDetector scans the system PATH to automatically find and configure AI agents. It returns true if new agents were discovered and can automatically select a default agent based on priority. The updated configuration can then be saved. ```csharp using AgentBridge.Core.Config; using Microsoft.Extensions.Logging; var loggerFactory = LoggerFactory.Create(b => b.AddConsole()); var logger = loggerFactory.CreateLogger("Detector"); // Start with empty or existing config var cfg = new AppConfig(); // Detect and configure all available agents // Returns true if any new agents were discovered bool modified = AgentDetector.DetectAndConfigure(cfg, logger); if (modified) { // Log discovered agents foreach (var (name, agentCfg) in cfg.Agents) { Console.WriteLine($"Found: {name} ({agentCfg.Type}) at {agentCfg.Command}"); } // Default agent is auto-selected by priority: // claude > codex > cursor > kimi > gemini > opencode > openclaw > copilot Console.WriteLine($"Default agent set to: {cfg.DefaultAgent}"); // Save the updated configuration ConfigManager.Save(cfg); } // Agent detection priority (ACP preferred over CLI): // - claude: claude-agent-acp (ACP) > claude (CLI) // - codex: codex-acp (ACP) > codex (CLI) // - cursor: agent acp (ACP only) // - kimi: kimi acp (ACP only) // - gemini: gemini --acp (ACP only) // - opencode: opencode acp (ACP only) // - openclaw: openclaw (ACP, requires gateway config) // - copilot: copilot (CLI only) ``` -------------------------------- ### Interact with Agents via WeChat Commands Source: https://context7.com/feiyun0112/agentbridge/llms.txt Commands used within WeChat to switch agents, send messages, and check status. ```text # Send message to the default agent Hello, can you help me write a Python function? # Send message to a specific agent (prefix with /{agentname}) /claude Explain how async/await works in JavaScript /codex Write a sorting algorithm in Go /copilot Review this code for security issues # Switch the default agent /claude > switch to claude /codex > switch to codex # Check current agent status /status > agent: claude > type: acp > model: sonnet # Show available commands /help > Available commands: > /{agentname} - Switch default agent > /{agentname} message - Send message to a specific agent > /status - Show current agent info > /help - Show this help message > > Agent Names: /claude /codex /cursor /kimi /gemini /openclaw /opencode /copilot ``` -------------------------------- ### Implement IAgent Interface in C# Source: https://context7.com/feiyun0112/agentbridge/llms.txt The IAgent interface defines the contract for agent implementations, requiring ChatAsync and Info methods. ```csharp using AgentBridge.Core.Agent; public interface IAgent { // conversationId maintains per-user conversation history across turns Task ChatAsync(string conversationId, string message, CancellationToken ct = default); AgentInfo Info(); } // Example usage with dependency injection public class MyService { private readonly IAgent _agent; public MyService(IAgent agent) { _agent = agent; } public async Task ProcessUserMessage(string userId, string message) { // userId serves as conversationId to maintain session history string response = await _agent.ChatAsync( conversationId: userId, message: message, ct: CancellationToken.None); Console.WriteLine($"Agent: {_agent.Info().Name}, Type: {_agent.Info().Type}"); return response; } } ``` -------------------------------- ### POST /api/send Source: https://context7.com/feiyun0112/agentbridge/llms.txt Sends a message to a specific WeChat user. Supports text, media files, or a combination of both. ```APIDOC ## POST /api/send ### Description Sends a text message or media file to a specified WeChat user ID. ### Method POST ### Endpoint /api/send ### Request Body - **to** (string) - Required - The WeChat user ID (wxid) of the recipient. - **text** (string) - Optional - The text content to send. - **media_url** (string) - Optional - The URL of the image, video, or file to send. ### Request Example { "to": "wxid_abc123", "text": "Hello from AgentBridge!", "media_url": "https://example.com/image.png" } ### Response #### Success Response (200) - **status** (string) - Returns "ok" upon successful dispatch. #### Error Responses - **400** - Returned if "to" is missing or if both "text" and "media_url" are missing. - **503** - Returned if no accounts are configured. - **500** - Returned if the send operation fails. ``` -------------------------------- ### Interact with AgentBridge HTTP API Source: https://context7.com/feiyun0112/agentbridge/llms.txt Send messages to WeChat users programmatically using the AgentBridge HTTP API. Supports text messages, media files, or a combination. Ensure the server is running and accessible. ```bash # Health check endpoint curl http://127.0.0.1:18088/health # Response: ok # Send a text message to a user curl -X POST http://127.0.0.1:18088/api/send \ -H "Content-Type: application/json" \ -d '{ "to": "wxid_abc123", "text": "Hello from AgentBridge!" }' # Response: {"status":"ok"} # Send a media file (image, video, or file) curl -X POST http://127.0.0.1:18088/api/send \ -H "Content-Type: application/json" \ -d '{ "to": "wxid_abc123", "media_url": "https://example.com/image.png" }' # Response: {"status":"ok"} # Send both text and media in one request curl -X POST http://127.0.0.1:18088/api/send \ -H "Content-Type: application/json" \ -d '{ "to": "wxid_abc123", "text": "Check out this diagram:", "media_url": "https://example.com/diagram.png" }' # Response: {"status":"ok"} # Error responses # Missing recipient: 400 "\"to\" is required." # Missing content: 400 "\"text\" or \"media_url\" is required." # No accounts: 503 "No accounts configured." # Send failure: 500 "Send failed: " ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.