### Manual Backend Setup and Run Source: https://github.com/punyamodi/autogen-web/blob/main/README.md This section details the manual steps to set up a Python virtual environment, install backend dependencies, and run the FastAPI application using Uvicorn. It's an alternative to using the start scripts. ```bash python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate pip install -r backend/requirements.txt python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000 --reload ``` -------------------------------- ### Start Application on macOS/Linux Source: https://github.com/punyamodi/autogen-web/blob/main/README.md This snippet shows how to make the start script executable and then run the autogen-web application on macOS or Linux systems. It requires the start.sh script to be present. ```bash chmod +x start.sh && ./start.sh ``` -------------------------------- ### Start Application on Windows Source: https://github.com/punyamodi/autogen-web/blob/main/README.md This command is used to start the autogen-web application on a Windows operating system. It assumes the necessary setup and environment configuration has been completed. ```bat start.bat ``` -------------------------------- ### Frontend JavaScript API Client Usage Source: https://context7.com/punyamodi/autogen-web/llms.txt Demonstrates how to use the JavaScript API client provided by the frontend to interact with the backend for session management. Includes examples for listing, creating, getting, updating, deleting sessions, and retrieving messages, modes, LLM config, and health status. ```javascript // List all sessions const sessions = await API.listSessions(); console.log(sessions); // [{id, name, mode, created_at, updated_at}, ...] // Create new session const newSession = await API.createSession("My Project", "coding_team"); console.log(newSession.id); // "uuid-string" // Get session details const session = await API.getSession("session-uuid"); // Update session await API.updateSession("session-uuid", { name: "Renamed Project" }); // Delete session await API.deleteSession("session-uuid"); // Get session messages const messages = await API.getMessages("session-uuid"); // Export session const exportData = await API.exportSession("session-uuid"); // Get available modes const modes = await API.getModes(); // Get LLM config const config = await API.getLLMConfig(); // Check health const health = await API.checkHealth(); console.log(health.llm_reachable); // true or false ``` -------------------------------- ### Docker Compose Startup Source: https://github.com/punyamodi/autogen-web/blob/main/README.md This command initiates the autogen-web application using Docker Compose. It builds the necessary images and starts the containers, simplifying the deployment process. It also includes instructions for configuring local LM Studio access within Docker. ```bash cp .env.example .env docker-compose up --build # For a local LM Studio instance on the host machine, set LLM_BASE_URL=http://host.docker.internal:1234/v1 in .env. ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/punyamodi/autogen-web/blob/main/README.md This code demonstrates copying the example environment file and editing it to configure LLM details. This is crucial for connecting the application to a language model backend. ```bash cp .env.example .env # Edit .env with your LLM details ``` -------------------------------- ### Get LLM Configuration (REST API) Source: https://context7.com/punyamodi/autogen-web/llms.txt Fetches the current configuration for the Large Language Model (LLM) backend. This includes the base URL, API key, model name, temperature, and timeout settings. The configuration is typically loaded from environment variables or uses default values. ```bash # Get current LLM config curl -X GET http://localhost:8000/api/config/llm ``` -------------------------------- ### GET /api/config/llm Source: https://context7.com/punyamodi/autogen-web/llms.txt Fetches the current Large Language Model (LLM) configuration, including base URL, API key, model name, temperature, and timeout settings. ```APIDOC ## GET /api/config/llm ### Description Returns the current LLM backend configuration, which is typically set via environment variables or uses default values. ### Method GET ### Endpoint /api/config/llm ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **base_url** (string) - The base URL for the LLM API. - **api_key** (string) - The API key for the LLM service (may be "NULL" if not set). - **model** (string) - The name or identifier of the LLM model being used. - **temperature** (number) - The sampling temperature for the LLM. - **timeout** (integer) - The timeout in seconds for LLM requests. #### Response Example ```json { "base_url": "http://localhost:1234/v1", "api_key": "NULL", "model": "local-model", "temperature": 0.1, "timeout": 600 } ``` ``` -------------------------------- ### Run Research Team Mode with Python Source: https://context7.com/punyamodi/autogen-web/llms.txt Starts the Research Team mode, a six-agent group focused on research tasks such as investigating topics and generating reports. It streams findings and verification steps. ```python from backend.agents.research_team import research_team_stream async def run_research(): async for message in research_team_stream( message="Research the current state of quantum computing and its practical applications", llm_config=llm_config ): print(f"[{message['sender']}]: {message['content'][:100]}...") ``` -------------------------------- ### GET /api/config/modes Source: https://context7.com/punyamodi/autogen-web/llms.txt Retrieves all available agent modes, including their names, descriptions, and associated agents. ```APIDOC ## GET /api/config/modes ### Description Returns all available agent team configurations with their descriptions and agent lists. ### Method GET ### Endpoint /api/config/modes ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **id** (string) - Unique identifier for the agent mode. - **name** (string) - Display name of the agent mode. - **description** (string) - A brief explanation of the agent mode's purpose. - **agents** (array of strings) - A list of agent roles included in this mode. - **icon** (string) - An identifier for an icon associated with the mode. #### Response Example ```json [ { "id": "pair_coder", "name": "Pair Coder", "description": "A two-agent setup with a CTO and an Executor. Best for focused coding tasks.", "agents": ["CTO", "Executor"], "icon": "code" } ] ``` ``` -------------------------------- ### Get Single Session Source: https://context7.com/punyamodi/autogen-web/llms.txt Retrieves details for a specific session by ID. Returns 404 if session not found. ```APIDOC ## GET /api/sessions/{session_id} ### Description Retrieves details for a specific session by ID. Returns 404 if session not found. ### Method GET ### Endpoint /api/sessions/{session_id} ### Parameters #### Path Parameters - **session_id** (string) - Required - The unique identifier of the session to retrieve. #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **id** (string) - Unique identifier for the session. - **name** (string) - Name of the session. - **mode** (string) - The agent mode configured for the session. - **created_at** (string) - Timestamp when the session was created (ISO 8601 format). - **updated_at** (string) - Timestamp when the session was last updated (ISO 8601 format). #### Error Response (404 Not Found) Returned if the session with the specified ID does not exist. #### Response Example ```json { "id": "550e8400-e29b-41d4-a716-446655440000", "name": "Python debugging session", "mode": "pair_coder", "created_at": "2024-01-15T10:30:00.000Z", "updated_at": "2024-01-15T14:22:00.000Z" } ``` ``` -------------------------------- ### Real-time Chat Connection (WebSocket API) Source: https://context7.com/punyamodi/autogen-web/llms.txt Establishes a WebSocket connection for real-time communication with agents. This allows for streaming responses and sending messages to the agents. The example demonstrates connecting, sending a message with configuration, and handling different types of incoming messages like 'connected', 'thinking', 'agent_message', 'done', and 'error'. ```javascript // JavaScript WebSocket connection example const sessionId = "550e8400-e29b-41d4-a716-446655440000"; const ws = new WebSocket(`ws://localhost:8000/ws/${sessionId}`); ws.onopen = () => { console.log("Connected to AgentForge"); // Send a message to agents ws.send(JSON.stringify({ type: "message", content: "Create a Python web scraper for news headlines", mode: "coding_team", config: { base_url: "http://localhost:1234/v1", api_key: "NULL", model: "local-model", temperature: 0.1, timeout: 600 } })); }; ws.onmessage = (event) => { const data = JSON.parse(event.data); switch (data.type) { case "connected": console.log(`Session connected: ${data.session_id}`); break; case "thinking": console.log("Agents are working..."); break; case "agent_message": console.log(`[${data.sender}]: ${data.content}`); break; case "done": console.log("Task completed"); break; case "error": console.error(`Error: ${data.content}`); break; case "pong": // Keepalive response break; } }; // Send periodic ping to keep connection alive setInterval(() => { if (ws.readyState === WebSocket.OPEN) { ws.send(JSON.stringify({ type: "ping" })); } }, 25000); ``` -------------------------------- ### Get Session Messages Source: https://context7.com/punyamodi/autogen-web/llms.txt Retrieves all messages for a session in chronological order. Includes both user messages and agent responses. ```APIDOC ## GET /api/sessions/{session_id}/messages ### Description Retrieves all messages for a session in chronological order. Includes both user messages and agent responses. ### Method GET ### Endpoint /api/sessions/{session_id}/messages ### Parameters #### Path Parameters - **session_id** (string) - Required - The unique identifier of the session whose messages are to be retrieved. #### Query Parameters None #### Request Body None ### Response #### Success Response (200 OK) - **id** (integer) - Unique identifier for the message. - **session_id** (string) - The ID of the session this message belongs to. - **sender** (string) - The entity that sent the message (e.g., "User", "CTO"). - **recipient** (string or null) - The intended recipient of the message, if applicable. - **content** (string) - The content of the message, potentially including markdown and code blocks. - **msg_type** (string) - The type of message (e.g., "user_message", "agent_message"). - **created_at** (string) - Timestamp when the message was created (ISO 8601 format). #### Error Response (404 Not Found) Returned if the session with the specified ID does not exist. #### Response Example ```json [ { "id": 1, "session_id": "550e8400-e29b-41d4-a716-446655440000", "sender": "User", "recipient": null, "content": "Write a Python function to calculate fibonacci numbers", "msg_type": "user_message", "created_at": "2024-01-15T10:31:00.000Z" }, { "id": 2, "session_id": "550e8400-e29b-41d4-a716-446655440000", "sender": "CTO", "recipient": null, "content": "I'll write an efficient fibonacci function using memoization...\n\n```python\ndef fibonacci(n, memo={}):\n if n in memo:\n return memo[n]\n if n <= 1:\n return n\n memo[n] = fibonacci(n-1, memo) + fibonacci(n-2, memo)\n return memo[n]\n```\n\nTERMINATE", "msg_type": "agent_message", "created_at": "2024-01-15T10:31:15.000Z" } ] ``` ``` -------------------------------- ### GET /api/config/health Source: https://context7.com/punyamodi/autogen-web/llms.txt Performs a health check on the system, including verifying connectivity to the LLM backend. ```APIDOC ## GET /api/config/health ### Description Performs a health check on the system, including verification of LLM backend connectivity. ### Method GET ### Endpoint /api/config/health ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **status** (string) - The overall health status of the system (e.g., "ok"). - **version** (string) - The version of the AgentForge system. - **llm_reachable** (boolean) - Indicates whether the LLM backend is currently reachable. - **llm_base_url** (string) - The base URL of the LLM backend being checked. #### Response Example (LLM reachable) ```json { "status": "ok", "version": "1.0.0", "llm_reachable": true, "llm_base_url": "http://localhost:1234/v1" } ``` #### Response Example (LLM unreachable) ```json { "status": "ok", "version": "1.0.0", "llm_reachable": false, "llm_base_url": "http://localhost:1234/v1" } ``` ``` -------------------------------- ### Get Available Agent Modes (REST API) Source: https://context7.com/punyamodi/autogen-web/llms.txt Retrieves a list of all available agent team configurations. Each configuration includes its ID, name, description, and the list of agents within that team. This endpoint is useful for understanding the different operational modes supported by the system. ```bash # Get all agent modes curl -X GET http://localhost:8000/api/config/modes ``` -------------------------------- ### List All Sessions (REST API) Source: https://context7.com/punyamodi/autogen-web/llms.txt Retrieves a list of all chat sessions, ordered by their last update time. The response includes metadata for each session such as its ID, name, configured agent mode, and creation/update timestamps. This endpoint is useful for getting an overview of ongoing or past agent interactions. ```bash curl -X GET http://localhost:8000/api/sessions # Response [ { "id": "550e8400-e29b-41d4-a716-446655440000", "name": "Python debugging session", "mode": "pair_coder", "created_at": "2024-01-15T10:30:00.000Z", "updated_at": "2024-01-15T14:22:00.000Z" }, { "id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "name": "Research project", "mode": "research", "created_at": "2024-01-14T09:00:00.000Z", "updated_at": "2024-01-14T16:45:00.000Z" } ] ``` -------------------------------- ### Pair Coder Mode Functionality (Python) Source: https://context7.com/punyamodi/autogen-web/llms.txt Demonstrates how to use the `pair_coder_stream` function to initiate a coding session with the Pair Coder agent team. This function streams messages from the agents, allowing for real-time observation of the coding process. The example shows setting up LLM configuration and handling the streamed output, including sender and content. ```python from backend.agents.pair_coder import pair_coder_stream # LLM configuration llm_config = { "seed": 42, "config_list": [{ "model": "gpt-4", "base_url": "https://api.openai.com/v1", "api_key": "your-api-key" }], "temperature": 0.1, "timeout": 600 } # Stream agent responses async def run_pair_coder(): async for message in pair_coder_stream( message="Write a function to merge two sorted arrays", llm_config=llm_config ): print(f"[{message['sender']}]: {message['content']}") # Output: # [CTO]: I'll implement an efficient merge function... # [Executor]: Exit code: 0, Output: [1, 2, 3, 4, 5, 6] # [CTO]: The function works correctly. TERMINATE ``` -------------------------------- ### Create New Session (REST API) Source: https://context7.com/punyamodi/autogen-web/llms.txt Creates a new chat session, allowing users to specify a name and an agent mode. The API returns the newly created session object, including a system-generated UUID for its unique identifier. This is the starting point for initiating a new AI agent conversation. ```bash curl -X POST http://localhost:8000/api/sessions \ -H "Content-Type: application/json" \ -d '{ "name": "Build REST API", "mode": "coding_team" }' # Response (201 Created) { "id": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "name": "Build REST API", "mode": "coding_team", "created_at": "2024-01-15T15:00:00.000Z", "updated_at": "2024-01-15T15:00:00.000Z" } ``` -------------------------------- ### Get Session Messages (REST API) Source: https://context7.com/punyamodi/autogen-web/llms.txt Retrieves all messages exchanged within a specific session, ordered chronologically. The response includes both user-initiated messages and agent responses, providing a complete conversation history. This is essential for reviewing past interactions or debugging. ```bash curl -X GET http://localhost:8000/api/sessions/550e8400-e29b-41d4-a716-446655440000/messages # Response [ { "id": 1, "session_id": "550e8400-e29b-41d4-a716-446655440000", "sender": "User", "recipient": null, "content": "Write a Python function to calculate fibonacci numbers", "msg_type": "user_message", "created_at": "2024-01-15T10:31:00.000Z" }, { "id": 2, "session_id": "550e8400-e29b-41d4-a716-446655440000", "sender": "CTO", "recipient": null, "content": "I'll write an efficient fibonacci function using memoization...\n\n```python\ndef fibonacci(n, memo={}):\n if n in memo:\n return memo[n]\n if n <= 1:\n return n\n memo[n] = fibonacci(n-1, memo) + fibonacci(n-2, memo)\n return memo[n]\n```\n\nTERMINATE", "msg_type": "agent_message", "created_at": "2024-01-15T10:31:15.000Z" } ] ``` -------------------------------- ### Get Single Session Details (REST API) Source: https://context7.com/punyamodi/autogen-web/llms.txt Retrieves detailed information about a specific chat session using its unique ID. If a session with the provided ID does not exist, the API will return a 404 Not Found error. This endpoint is used to fetch the current state and metadata of a particular session. ```bash curl -X GET http://localhost:8000/api/sessions/550e8400-e29b-41d4-a716-446655440000 # Response { "id": "550e8400-e29b-41d4-a716-446655440000", "name": "Python debugging session", "mode": "pair_coder", "created_at": "2024-01-15T10:30:00.000Z", "updated_at": "2024-01-15T14:22:00.000Z" } ``` -------------------------------- ### LM Studio Configuration Source: https://context7.com/punyamodi/autogen-web/llms.txt Sets up environment variables for connecting to a locally running LLM via LM Studio. This configuration uses a default local URL, a NULL API key, and specifies a local model. ```bash # Configure for LM Studio (default) LLM_BASE_URL=http://localhost:1234/v1 LLM_API_KEY=NULL LLM_MODEL=local-model LLM_TEMPERATURE=0.1 LLM_TIMEOUT=600 ``` -------------------------------- ### Build OpenAI-Compatible Model Client with Python Source: https://context7.com/punyamodi/autogen-web/llms.txt Creates a model client compatible with OpenAI's API using provided LLM configuration. This client can then be used to initialize AutoGen agents. ```python from backend.agents.base import build_model_client from autogen_agentchat.agents import AssistantAgent llm_config = { "config_list": [{ "model": "gpt-4-turbo", "base_url": "https://api.openai.com/v1", "api_key": "sk-your-key" }] } # Create model client model_client = build_model_client(llm_config) # Use with AutoGen agents assistant = AssistantAgent( name="Assistant", model_client=model_client, system_message="You are a helpful coding assistant." ) ``` -------------------------------- ### Environment Variables for LLM Configuration Source: https://context7.com/punyamodi/autogen-web/llms.txt Demonstrates how to configure LLM backend settings using environment variables or a .env file. This includes API endpoint, key, model name, temperature, and timeout. ```bash # .env file example # LLM Backend Configuration LLM_BASE_URL=http://localhost:1234/v1 # OpenAI-compatible API endpoint LLM_API_KEY=NULL # API key (NULL for local models) LLM_MODEL=local-model # Model identifier LLM_TEMPERATURE=0.1 # Sampling temperature (0.0-2.0) LLM_TIMEOUT=600 # Request timeout in seconds ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/punyamodi/autogen-web/blob/main/README.md This snippet shows how to clone the autogen-web repository from GitHub and navigate into the project directory. It's the initial step for setting up the project locally. ```bash git clone https://github.com/punyamodi/autogen-web cd autogen-web ``` -------------------------------- ### Docker LM Studio Configuration Source: https://context7.com/punyamodi/autogen-web/llms.txt Provides configuration for connecting to a local LM Studio instance when running within a Docker container. It uses `host.docker.internal` to access the host machine's services. ```bash # For Docker with host LM Studio, use host.docker.internal LLM_BASE_URL=http://host.docker.internal:1234/v1 LLM_API_KEY=NULL LLM_MODEL=local-model ``` -------------------------------- ### Database and Server Configuration Source: https://context7.com/punyamodi/autogen-web/llms.txt Defines essential environment variables for database connection (SQLAlchemy) and server settings (host, port, debug mode). These are typically set in a .env file. ```bash # Database Configuration DATABASE_URL=sqlite:///./agentforge.db # SQLAlchemy database URL WORKSPACE_DIR=./backend/workspace # Code execution workspace # Server Configuration HOST=0.0.0.0 # Server bind address PORT=8000 # Server port DEBUG=false # Debug mode ``` -------------------------------- ### Run Agent Stream with Python Source: https://context7.com/punyamodi/autogen-web/llms.txt Provides the main entry point for running any agent mode with streaming responses. It handles routing to the correct agent team based on the specified mode. ```python from backend.agents.base import run_stream async def process_user_request(message: str, mode: str): llm_config = { "seed": 42, "config_list": [{ "model": "local-model", "base_url": "http://localhost:1234/v1", "api_key": "NULL" }], "temperature": 0.1, "timeout": 600 } # Supported modes: "pair_coder", "coding_team", "jarvis", "research" async for msg in run_stream(message, mode, llm_config): yield msg # {"type": "agent_message", "sender": "...", "content": "..."} # Usage async for response in process_user_request("Build a REST API", "coding_team"): print(response) ``` -------------------------------- ### OpenAI API Configuration Source: https://context7.com/punyamodi/autogen-web/llms.txt Configures environment variables for connecting to the OpenAI API. This includes the base URL, API key, model name, temperature, and timeout settings. ```bash # Configure for OpenAI LLM_BASE_URL=https://api.openai.com/v1 LLM_API_KEY=sk-your-openai-api-key LLM_MODEL=gpt-4-turbo LLM_TEMPERATURE=0.1 LLM_TIMEOUT=120 ``` -------------------------------- ### Frontend JavaScript WebSocket Client Class Source: https://context7.com/punyamodi/autogen-web/llms.txt Illustrates the usage of the WebSocket client class for real-time communication with the backend. It covers connection management, handling incoming messages, sending messages with custom LLM configurations, checking connection status, and disconnecting. ```javascript // Create WebSocket client const wsClient = new WebSocketClient( sessionId, (data) => { // Handle incoming messages if (data.type === "agent_message") { appendMessage(data.sender, data.content); } else if (data.type === "done") { enableInput(); } else if (data.type === "error") { showError(data.content); } }, () => { // Handle connection close console.log("Disconnected"); } ); // Connect wsClient.connect(); // Send message with custom LLM config wsClient.send({ type: "message", content: "Help me write unit tests", mode: "pair_coder", config: { base_url: "http://localhost:1234/v1", api_key: "NULL", model: "local-model", temperature: 0.2, timeout: 600 } }); // Check connection status if (wsClient.isConnected()) { console.log("WebSocket is open"); } // Disconnect when done wsClient.disconnect(); ``` -------------------------------- ### Project Structure Overview Source: https://github.com/punyamodi/autogen-web/blob/main/README.md This illustrates the directory structure of the autogen-web project, categorizing files into backend, frontend, and root configuration/script directories. It helps in understanding the organization of the codebase. ```tree agentforge/ ├── backend/ │ ├── main.py # FastAPI application │ ├── requirements.txt │ ├── agents/ │ │ ├── base.py # Capturing agent base classes │ │ ├── pair_coder.py # 2-agent coding session │ │ ├── coding_team.py # 6-agent research and coding team │ │ ├── jarvis.py # 9-agent Jarvis system │ │ └── research_team.py # 6-agent research team │ ├── api/ │ │ ├── chat.py # WebSocket streaming endpoint │ │ ├── sessions.py # Session CRUD + export │ │ └── config.py # LLM config and health check │ └── core/ │ ├── database.py # SQLAlchemy models │ ├── settings.py # Pydantic settings │ └── schemas.py # Request/response schemas ├── frontend/ │ ├── index.html # Single-page application │ └── assets/ │ ├── css/styles.css │ └── js/ │ ├── app.js # Main state and event handling │ ├── api.js # REST and WebSocket clients │ ├── chat.js # Chat UI rendering │ └── settings.js # Settings modal ├── .env.example ├── Dockerfile ├── docker-compose.yml ├── start.sh └── start.bat ``` -------------------------------- ### Run Jarvis Mode with Python Source: https://context7.com/punyamodi/autogen-web/llms.txt Activates Jarvis Mode, a comprehensive nine-agent assistant for tasks like algorithm optimization and complexity analysis. It streams responses from specialized agents. ```python from backend.agents.jarvis import jarvis_stream async def run_jarvis(): async for message in jarvis_stream( message="Help me optimize this algorithm and explain the time complexity", llm_config=llm_config ): print(f"[{message['sender']}]: {message['content'][:100]}...") ``` -------------------------------- ### Run Coding Team Mode with Python Source: https://context7.com/punyamodi/autogen-web/llms.txt Initiates the Coding Team mode, a six-agent system designed for complex software projects. It takes a task description and LLM configuration to stream agent interactions. ```python from backend.agents.coding_team import coding_team_stream async def run_coding_team(): task = """ Build a data pipeline that: 1. Reads CSV files from a directory 2. Cleans and validates the data 3. Performs statistical analysis 4. Generates a summary report """ async for message in coding_team_stream(task, llm_config): print(f"[{message['sender']}]: {message['content'][:100]}...") ``` -------------------------------- ### Build Local Code Executor with Python Source: https://context7.com/punyamodi/autogen-web/llms.txt Initializes a local code executor designed for safely running agent-generated code within a specified directory. It's used to create a CodeExecutorAgent. ```python from backend.agents.base import build_code_executor from autogen_agentchat.agents import CodeExecutorAgent # Create executor with custom workspace code_executor = build_code_executor(work_dir="backend/workspace") # Create code executor agent executor_agent = CodeExecutorAgent( name="Executor", code_executor=code_executor, description="Executes code and returns results" ) ``` -------------------------------- ### Frontend JavaScript API Client Source: https://context7.com/punyamodi/autogen-web/llms.txt This section details the usage of the provided JavaScript API client for interacting with the AgentForge backend, including session management, message retrieval, and configuration. ```APIDOC ## Frontend JavaScript API Client ### Description The frontend provides a JavaScript API client for interacting with the backend. ### API Client Usage ```javascript // List all sessions const sessions = await API.listSessions(); console.log(sessions); // [{id, name, mode, created_at, updated_at}, ...] // Create new session const newSession = await API.createSession("My Project", "coding_team"); console.log(newSession.id); // "uuid-string" // Get session details const session = await API.getSession("session-uuid"); // Update session await API.updateSession("session-uuid", { name: "Renamed Project" }); // Delete session await API.deleteSession("session-uuid"); // Get session messages const messages = await API.getMessages("session-uuid"); // Export session const exportData = await API.exportSession("session-uuid"); // Get available modes const modes = await API.getModes(); // Get LLM config const config = await API.getLLMConfig(); // Check health const health = await API.checkHealth(); console.log(health.llm_reachable); // true or false ``` ``` -------------------------------- ### WebSocket Client Class Source: https://context7.com/punyamodi/autogen-web/llms.txt This section describes the WebSocket client class for managing real-time communication with AgentForge, including connection, message sending, and disconnection. ```APIDOC ## WebSocket Client Class ### Description Provides connection management with automatic ping/pong keepalive. ### WebSocket Client Usage ```javascript // Create WebSocket client const wsClient = new WebSocketClient( sessionId, (data) => { // Handle incoming messages if (data.type === "agent_message") { appendMessage(data.sender, data.content); } else if (data.type === "done") { enableInput(); } else if (data.type === "error") { showError(data.content); } }, () => { // Handle connection close console.log("Disconnected"); } ); // Connect wsClient.connect(); // Send message with custom LLM config wsClient.send({ type: "message", content: "Help me write unit tests", mode: "pair_coder", config: { base_url: "http://localhost:1234/v1", api_key: "NULL", model: "local-model", temperature: 0.2, timeout: 600 } }); // Check connection status if (wsClient.isConnected()) { console.log("WebSocket is open"); } // Disconnect when done wsClient.disconnect(); ``` ``` -------------------------------- ### List All Sessions Source: https://context7.com/punyamodi/autogen-web/llms.txt Retrieves all chat sessions ordered by most recently updated. Returns session metadata including ID, name, mode, and timestamps. ```APIDOC ## GET /api/sessions ### Description Retrieves all chat sessions ordered by most recently updated. Returns session metadata including ID, name, mode, and timestamps. ### Method GET ### Endpoint /api/sessions ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **id** (string) - Unique identifier for the session. - **name** (string) - Name of the session. - **mode** (string) - The agent mode configured for the session (e.g., "pair_coder", "coding_team", "jarvis", "research"). - **created_at** (string) - Timestamp when the session was created (ISO 8601 format). - **updated_at** (string) - Timestamp when the session was last updated (ISO 8601 format). #### Response Example ```json [ { "id": "550e8400-e29b-41d4-a716-446655440000", "name": "Python debugging session", "mode": "pair_coder", "created_at": "2024-01-15T10:30:00.000Z", "updated_at": "2024-01-15T14:22:00.000Z" } ] ``` ``` -------------------------------- ### Configuration API Source: https://github.com/punyamodi/autogen-web/blob/main/README.md Endpoints for retrieving various configuration details, including available agent modes, LLM configuration, and system health status. ```APIDOC ## GET /api/config/modes ### Description Retrieves a list of all available agent modes that can be used for chat sessions. ### Method GET ### Endpoint `/api/config/modes` ``` ```APIDOC ## GET /api/config/llm ### Description Retrieves the current configuration details for the Large Language Model (LLM) being used. ### Method GET ### Endpoint `/api/config/llm` ``` ```APIDOC ## GET /api/config/health ### Description Performs a health check on the system, including verifying reachability to the LLM. ### Method GET ### Endpoint `/api/config/health` ``` -------------------------------- ### Create New Session Source: https://context7.com/punyamodi/autogen-web/llms.txt Creates a new chat session with specified name and agent mode. Returns the created session object with auto-generated UUID. ```APIDOC ## POST /api/sessions ### Description Creates a new chat session with specified name and agent mode. Returns the created session object with auto-generated UUID. ### Method POST ### Endpoint /api/sessions ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (string) - Required - The desired name for the new session. - **mode** (string) - Required - The agent mode to use for the session (e.g., "pair_coder", "coding_team", "jarvis", "research"). ### Request Example ```json { "name": "Build REST API", "mode": "coding_team" } ``` ### Response #### Success Response (201 Created) - **id** (string) - Unique identifier for the newly created session. - **name** (string) - Name of the session. - **mode** (string) - The agent mode configured for the session. - **created_at** (string) - Timestamp when the session was created (ISO 8601 format). - **updated_at** (string) - Timestamp when the session was last updated (ISO 8601 format). #### Response Example ```json { "id": "7c9e6679-7425-40de-944b-e07fc1f90ae7", "name": "Build REST API", "mode": "coding_team", "created_at": "2024-01-15T15:00:00.000Z", "updated_at": "2024-01-15T15:00:00.000Z" } ``` ``` -------------------------------- ### WebSocket /ws/{session_id} Source: https://context7.com/punyamodi/autogen-web/llms.txt Establishes a real-time WebSocket connection for bidirectional communication with agents. Supports sending messages, receiving status updates, and streaming agent responses. ```APIDOC ## WebSocket /ws/{session_id} ### Description Connect to the WebSocket endpoint for real-time agent communication with streaming responses. This endpoint allows for interactive sessions where messages can be sent and received in real-time. ### Method WebSocket Upgrade ### Endpoint /ws/{session_id} ### Parameters #### Path Parameters - **session_id** (string) - Required - The unique identifier for the chat session. #### Query Parameters None #### Request Body (for sending messages) - **type** (string) - Required - The type of message (e.g., "message", "ping"). - **content** (string) - The message content to send to the agents. - **mode** (string) - The agent mode to use for the session. - **config** (object) - Optional LLM configuration for the session. - **base_url** (string) - LLM API base URL. - **api_key** (string) - LLM API key. - **model** (string) - LLM model name. - **temperature** (number) - LLM temperature setting. - **timeout** (integer) - LLM request timeout. ### Request Example (Sending a message) ```javascript { "type": "message", "content": "Create a Python web scraper for news headlines", "mode": "coding_team", "config": { "base_url": "http://localhost:1234/v1", "api_key": "NULL", "model": "local-model", "temperature": 0.1, "timeout": 600 } } ``` ### Response #### Message Types - **connected**: Indicates a successful connection to the session. - **thinking**: Notifies that agents are currently processing a request. - **agent_message**: Contains a message from an agent, including sender and content. - **done**: Signals that a task has been completed. - **error**: Reports an error that occurred during processing. - **pong**: A keepalive response to a "ping" message. #### Response Example (Agent Message) ```json { "type": "agent_message", "sender": "CTO", "content": "I will write a Python function to scrape news headlines." } ``` ``` -------------------------------- ### Export Session Source: https://context7.com/punyamodi/autogen-web/llms.txt Exports complete session data including all messages as JSON. Useful for backup or analysis. ```APIDOC ## GET /api/sessions/{session_id}/export ### Description Exports complete session data including all messages as JSON. Useful for backup or analysis. ### Method GET ### Endpoint /api/sessions/{session_id}/export ### Parameters #### Path Parameters - **session_id** (string) - Required - The unique identifier of the session to export. #### Query Parameters None #### Request Body None ### Response #### Success Response (200 OK) Returns a JSON object containing the entire session data, including all messages. #### Error Response (404 Not Found) Returned if the session with the specified ID does not exist. #### Response Example ```json { "session_id": "550e8400-e29b-41d4-a716-446655440000", "session_name": "Python debugging session", "session_mode": "pair_coder", "created_at": "2024-01-15T10:30:00.000Z", "updated_at": "2024-01-15T14:22:00.000Z", "messages": [ { "id": 1, "session_id": "550e8400-e29b-41d4-a716-446655440000", "sender": "User", "recipient": null, "content": "Write a Python function to calculate fibonacci numbers", "msg_type": "user_message", "created_at": "2024-01-15T10:31:00.000Z" }, { "id": 2, "session_id": "550e8400-e29b-41d4-a716-446655440000", "sender": "CTO", "recipient": null, "content": "I'll write an efficient fibonacci function using memoization...\n\n```python\ndef fibonacci(n, memo={}):\n if n in memo:\n return memo[n]\n if n <= 1:\n return n\n memo[n] = fibonacci(n-1, memo) + fibonacci(n-2, memo)\n return memo[n]\n```\n\nTERMINATE", "msg_type": "agent_message", "created_at": "2024-01-15T10:31:15.000Z" } ] } ``` ``` -------------------------------- ### Real-time Agent Chat Source: https://github.com/punyamodi/autogen-web/blob/main/README.md Establishes a WebSocket connection for real-time agent chat within a specific session. ```APIDOC ## WS /ws/{session_id} ### Description Provides real-time, bidirectional communication for agent chat using WebSockets. Clients can send and receive messages within a given session. ### Method WS ### Endpoint `/ws/{session_id}` ### Parameters #### Path Parameters - **session_id** (string) - Required - The unique identifier for the chat session. ``` -------------------------------- ### Health Check (REST API) Source: https://context7.com/punyamodi/autogen-web/llms.txt Performs a health check on the system, including verifying connectivity to the LLM backend. It returns the system status, version, and a boolean indicating whether the LLM is reachable, along with its base URL. ```bash # Check system health curl -X GET http://localhost:8000/api/config/health ``` -------------------------------- ### Export Session Data (REST API) Source: https://context7.com/punyamodi/autogen-web/llms.txt Exports the entire content of a session, including all messages, in JSON format. This functionality is valuable for data archival, offline analysis, or migrating session data. The endpoint returns a JSON object representing the complete session. ```bash curl -X GET http://localhost:8000/api/sessions/550e8400-e29b-41d4-a716-446655440000/export ``` -------------------------------- ### Pair Coder Mode Stream Source: https://context7.com/punyamodi/autogen-web/llms.txt Initiates a streaming session with the 'Pair Coder' agent mode, designed for focused coding tasks. This function allows for real-time feedback and code execution results. ```APIDOC ## Pair Coder Mode Stream ### Description This function initiates a streaming session using the 'pair_coder' agent mode. It's designed for focused coding tasks, providing real-time messages from the 'CTO' and 'Executor' agents. ### Method Stream (async iterator) ### Endpoint N/A (This is a function call within the backend) ### Parameters - **message** (string) - Required - The coding task or prompt for the agents. - **llm_config** (object) - Required - Configuration for the Large Language Model. - **seed** (integer) - Seed for reproducibility. - **config_list** (array of objects) - List of LLM provider configurations. - **model** (string) - The LLM model to use. - **base_url** (string) - The API base URL for the LLM. - **api_key** (string) - The API key for the LLM service. - **temperature** (number) - Sampling temperature for the LLM. - **timeout** (integer) - Timeout in seconds for LLM requests. ### Request Example (Python) ```python llm_config = { "seed": 42, "config_list": [ { "model": "gpt-4", "base_url": "https://api.openai.com/v1", "api_key": "your-api-key" } ], "temperature": 0.1, "timeout": 600 } async for message in pair_coder_stream( message="Write a function to merge two sorted arrays", llm_config=llm_config ): print(f"[{message['sender']}]: {message['content']}") ``` ### Response #### Success Response (Streamed Messages) Each message in the stream is a dictionary containing: - **sender** (string) - The agent sending the message (e.g., "CTO", "Executor"). - **content** (string) - The message content, which could be code, explanations, or execution results. #### Response Example (within the stream) ```json { "sender": "CTO", "content": "I'll implement an efficient merge function..." } ``` ```json { "sender": "Executor", "content": "Exit code: 0, Output: [1, 2, 3, 4, 5, 6]" } ``` ```json { "sender": "CTO", "content": "The function works correctly. TERMINATE" } ``` ```