### Quick Start: LangGraph Platform Ruby SDK Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md A concise example demonstrating the basic usage of the LangGraph Platform Ruby SDK. It shows how to initialize the client, create an assistant, create a thread, and run the assistant within that thread. ```ruby require 'langgraph_platform' # Initialize the client client = LanggraphPlatform::Client.new( api_key: 'your-api-key-here', base_url: 'https://api.langchain.com' # For local development, use http://127.0.0.1:2024 ) # Create an assistant assistant = client.assistants.create( graph_id: 'my-graph', name: 'My Assistant', config: { recursion_limit: 10 } ) # Create a thread thread = client.threads.create( metadata: { user_id: 'user123' } ) # Run the assistant run = client.runs.create( thread.thread_id, assistant_id: assistant.assistant_id, input: { message: 'Hello, world!' } ) puts "Run status: #{run.status}" ``` -------------------------------- ### Complete Workflow Example Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Provides a full end-to-end example of using the Langgraph Platform client, including creating an assistant, a thread, executing a run with streaming, and managing data. ```APIDOC ## Complete Workflow Example Full end-to-end workflow with error handling ### Method N/A (Client-side orchestration) ### Description This example demonstrates a complete lifecycle of interacting with the Langgraph Platform API: creating an assistant, initiating a thread, running a model with streaming output, retrieving the thread's state, storing conversation data, and finally cleaning up created resources. It also incorporates basic error handling. ### Request Example ```ruby require 'langgraph_platform' client = LanggraphPlatform::Client.new( api_key: 'fake-api-key', base_url: 'http://127.0.0.1:2024' ) try # 1. Create assistant puts "Creating assistant..." assistant = client.assistants.create( graph_id: 'chat', name: 'Support Bot', config: { recursion_limit: 10 }, metadata: { version: '1.0' } ) puts "Assistant created: #{assistant.assistant_id}" # 2. Create thread puts "Creating thread..." thread = client.threads.create( metadata: { user_id: 'user-789', session: 'demo' } ) puts "Thread created: #{thread.thread_id}" # 3. Execute run with streaming puts "Executing run with streaming..." client.runs.stream( thread.thread_id, assistant_id: assistant.assistant_id, input: { messages: [ { role: 'user', content: 'Hello! Can you help me?' } ] }, stream_mode: 'messages' ) do |type, data, id, reconnection_time| if type == 'messages/partial' && data.is_a?(Array) print data.first['content'] elsif type == 'messages/complete' puts "\n" end end # 4. Get final state state = client.threads.state(thread.thread_id) puts "Final state: #{state.values}" # 5. Store conversation data client.store.put( 'conversations', "conv-#{thread.thread_id}", value: { thread_id: thread.thread_id, user_id: 'user-789', messages: state.values['messages'], completed_at: Time.now.to_s } ) puts "Conversation saved" # 6. Cleanup client.assistants.delete(assistant.assistant_id) puts "Cleaned up resources" rescue LanggraphPlatform::Errors::APIError => e puts "API Error: #{e.message}" rescue StandardError => e puts "Error: #{e.message}" end ``` ### Response N/A (Client-side processing and output) ``` -------------------------------- ### Install LangGraph Platform Ruby SDK Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md Instructions for installing the LangGraph Platform Ruby SDK using Bundler or directly via gem install. This is the first step to integrating the SDK into a Ruby application. ```ruby gem 'langgraph-platform' ``` ```bash $ bundle install ``` ```bash $ gem install langgraph-platform ``` -------------------------------- ### Store Operations with LangGraph Platform Ruby SDK Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md Examples for performing store operations using the LangGraph Platform Ruby SDK. This includes putting (storing) and getting (retrieving) data from a namespace. These operations are also under development. ```ruby # Store data client.store.put('namespace', 'key', { data: 'value' }) # Retrieve data item = client.store.get('namespace', 'key') ``` -------------------------------- ### Complete Langgraph Platform Workflow Example in Ruby Source: https://context7.com/gysmuller/langgraph-platform/llms.txt This Ruby example illustrates a full end-to-end workflow using the langgraph_platform gem. It covers creating an assistant, creating a thread, executing a run with streaming messages, retrieving the thread's state, storing conversation data, and finally cleaning up by deleting the created assistant. Basic error handling for API and standard errors is included. ```ruby require 'langgraph_platform' client = LanggraphPlatform::Client.new( api_key: 'fake-api-key', base_url: 'http://127.0.0.1:2024' ) begin # 1. Create assistant puts "Creating assistant..." assistant = client.assistants.create( graph_id: 'chat', name: 'Support Bot', config: { recursion_limit: 10 }, metadata: { version: '1.0' } ) puts "Assistant created: #{assistant.assistant_id}" # 2. Create thread puts "Creating thread..." thread = client.threads.create( metadata: { user_id: 'user-789', session: 'demo' } ) puts "Thread created: #{thread.thread_id}" # 3. Execute run with streaming puts "Executing run with streaming..." client.runs.stream( thread.thread_id, assistant_id: assistant.assistant_id, input: { messages: [ { role: 'user', content: 'Hello! Can you help me?' } ] }, stream_mode: 'messages' ) do |type, data, id, reconnection_time| if type == 'messages/partial' && data.is_a?(Array) print data.first['content'] elsif type == 'messages/complete' puts "\n" end end # 4. Get final state state = client.threads.state(thread.thread_id) puts "Final state: #{state.values}" # 5. Store conversation data client.store.put( 'conversations', "conv-#{thread.thread_id}", value: { thread_id: thread.thread_id, user_id: 'user-789', messages: state.values['messages'], completed_at: Time.now.to_s } ) puts "Conversation saved" # 6. Cleanup client.assistants.delete(assistant.assistant_id) puts "Cleaned up resources" rescue LanggraphPlatform::Errors::APIError => e puts "API Error: #{e.message}" rescue StandardError => e puts "Error: #{e.message}" end ``` -------------------------------- ### Manage Assistants with LangGraph Platform Ruby SDK Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md Code examples for managing assistants using the LangGraph Platform Ruby SDK. Includes creating, finding, searching, updating, and deleting assistants with their associated configurations and metadata. ```ruby # Create an assistant assistant = client.assistants.create( graph_id: 'my-graph', name: 'My Assistant', config: { recursion_limit: 10 }, metadata: { version: '1.0' } ) # Find an assistant assistant = client.assistants.find('assistant-id') # Search assistants assistants = client.assistants.search( metadata: { version: '1.0' }, limit: 10 ) # Update an assistant client.assistants.update('assistant-id', name: 'Updated Name') # Delete an assistant client.assistants.delete('assistant-id') ``` -------------------------------- ### Create Assistant Runs and Enable Webhook Notifications with Ruby Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Demonstrates creating a simple assistant run on a thread and creating a run with webhook notification, configuration, and metadata. Requires assistant and thread IDs. Returns run details and confirms webhook setup. ```Ruby # Create a simple run run = client.runs.create( 'thread-id-here', assistant_id: 'assistant-id-here', input: { messages: [ { role: 'user', content: 'Hello, I need help with my account' } ] } ) puts \"Run ID: #{run.run_id}\" puts \"Status: #{run.status}\" puts \"Thread ID: #{run.thread_id}\" # Create a run with webhook notification run = client.runs.create( 'thread-id-here', assistant_id: 'assistant-id-here', input: { messages: [{ role: 'user', content: 'Process this request' }] }, webhook: 'https://your-app.com/webhooks/langgraph', config: { max_tokens: 500 }, metadata: { priority: 'high' } ) puts \"Run created with webhook: #{run.run_id}\" ``` -------------------------------- ### List MCP Resources (GET) Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Lists all available resources managed by MCP. ```APIDOC ## GET /mcp/resources ### Description Lists all available resources managed by MCP. ### Method GET ### Endpoint `/mcp/resources` ### Parameters None ### Response #### Success Response (200) - **resources** (array) - An array of resource objects. - **uri** (string) - The unique identifier (URI) of the resource. - **name** (string) - The human-readable name of the resource. - **mime_type** (string) - The MIME type of the resource content. #### Response Example ```json [ { "uri": "resource://documents/readme", "name": "README.md", "mime_type": "text/markdown" }, { "uri": "resource://data/config.json", "name": "Configuration Data", "mime_type": "application/json" } ] ``` ``` -------------------------------- ### List and Complete MCP Prompts Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Illustrates how to work with MCP prompts, including listing available prompts, getting specific prompt details, and completing prompts with dynamic arguments. This facilitates prompt engineering and execution within the platform. ```ruby # List all available prompts prompts = client.mcp.list_prompts prompts.each do |prompt| puts "Prompt: #{prompt['name']}" puts "Description: #{prompt['description']}" puts "Arguments: #{prompt['arguments']}" end # Get specific prompt details prompt = client.mcp.get_prompt( name: 'code_review', arguments: { language: 'ruby', style: 'detailed' } ) puts "Prompt template: #{prompt}" # Complete a prompt result = client.mcp.complete_prompt( name: 'code_review', arguments: { language: 'ruby', code: 'def hello\n puts "Hello, World!"\nend', focus: 'best_practices' } ) puts "Completion: #{result['messages']}" ``` -------------------------------- ### List MCP Tools (GET) Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Lists all available tools that can be executed via the Model Context Protocol (MCP). ```APIDOC ## GET /mcp/tools ### Description Lists all available tools that can be executed via the Model Context Protocol (MCP). ### Method GET ### Endpoint `/mcp/tools` ### Parameters None ### Response #### Success Response (200) - **tools** (array) - An array of tool objects. - **name** (string) - The name of the tool. - **description** (string) - A description of the tool's functionality. - **parameters** (object) - A schema defining the parameters the tool accepts. #### Response Example ```json { "tools": [ { "name": "calculator", "description": "Performs arithmetic operations.", "parameters": {"type": "object", "properties": {"operation": {"type": "string"}, "numbers": {"type": "array", "items": {"type": "number"}}}} }, { "name": "web_search", "description": "Searches the web for information.", "parameters": {"type": "object", "properties": {"query": {"type": "string"}, "num_results": {"type": "integer"}}} } ] } ``` ``` -------------------------------- ### List MCP Prompts (GET) Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Lists all available prompts that can be completed via MCP. ```APIDOC ## GET /mcp/prompts ### Description Lists all available prompts that can be completed via MCP. ### Method GET ### Endpoint `/mcp/prompts` ### Parameters None ### Response #### Success Response (200) - **prompts** (array) - An array of prompt objects. - **name** (string) - The name of the prompt. - **description** (string) - A description of the prompt's purpose. - **arguments** (object) - A schema defining the expected arguments for the prompt. #### Response Example ```json [ { "name": "code_review", "description": "Reviews code for quality and best practices.", "arguments": {"language": "string", "code": "string", "focus": "string"} }, { "name": "text_summarization", "description": "Summarizes a given text.", "arguments": {"text": "string", "max_length": "integer"} } ] ``` ``` -------------------------------- ### Langgraph Webhook Integration for Runs (Ruby) Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md Shows how to configure webhooks for LangGraph API calls, enabling asynchronous processing of run completions. This example covers setting up webhooks for thread-based, stateless, and streaming runs. ```ruby # Thread-based runs with webhooks run = client.runs.create( thread.thread_id, assistant_id: assistant.assistant_id, input: { message: 'Process this data' }, webhook: 'https://your-app.com/webhooks/langgraph' ) # Stateless runs with webhooks client.runs.create_stateless( assistant_id: assistant.assistant_id, input: { message: 'Process this data' }, webhook: 'https://your-app.com/webhooks/langgraph' ) # Streaming runs with webhooks client.runs.stream( thread.thread_id, assistant_id: assistant.assistant_id, input: { message: 'Process this data' }, webhook: 'https://your-app.com/webhooks/langgraph' ) do |type, data, id, reconnection_time| # Handle streaming events end ``` -------------------------------- ### Search, Update, and Delete LangGraph Platform Assistants Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Provides Ruby code examples for searching assistants by metadata, finding a specific assistant, updating an existing assistant's configuration, and deleting an assistant. ```ruby # Search for assistants by metadata assistants = client.assistants.search( metadata: { department: 'support', version: '1.0' }, limit: 20, offset: 0 ) assistants.each do |asst| puts "Found: #{asst.assistant_id} - #{asst.name}" end # Find a specific assistant assistant = client.assistants.find('assistant-id-here') puts "Retrieved: #{assistant.name}" # Update assistant configuration updated = client.assistants.update( 'assistant-id-here', name: 'Updated Customer Support Assistant', config: { recursion_limit: 15 }, metadata: { version: '1.1', updated_at: Time.now.to_s } ) puts "Updated to version: #{updated.metadata['version']}" # Delete an assistant client.assistants.delete('assistant-id-here') puts "Assistant deleted successfully" ``` -------------------------------- ### Manage Threads with LangGraph Platform Ruby SDK Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md Examples of managing threads using the LangGraph Platform Ruby SDK. Covers creating threads, retrieving and updating their state, accessing their history, and searching for threads based on status. ```ruby # Create a thread thread = client.threads.create( metadata: { user_id: 'user123' } ) # Get thread state state = client.threads.state(thread.thread_id) # Update thread state client.threads.update_state( thread.thread_id, values: { key: 'value' } ) # Get thread history history = client.threads.history(thread.thread_id, limit: 10) # Search threads threads = client.threads.search( status: 'idle', limit: 10 ) ``` -------------------------------- ### Retrieve Data (GET) Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Retrieves a specific item from the store by namespace and key. ```APIDOC ## GET /store/namespace/:namespace/key/:key ### Description Retrieves a specific item from the store by namespace and key. ### Method GET ### Endpoint `/store/namespace/:namespace/key/:key` ### Parameters #### Path Parameters - **namespace** (string) - Required - The namespace of the item. - **key** (string) - Required - The key of the item. ### Response #### Success Response (200) - **key** (string) - The key of the retrieved item. - **value** (object) - The retrieved value. - **namespace** (string) - The namespace of the retrieved item. #### Response Example ```json { "key": "user-123", "value": { "theme": "dark", "language": "en", "notifications": true }, "namespace": "user_preferences" } ``` ``` -------------------------------- ### Get Specific MCP Tool (GET) Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Retrieves detailed information about a specific MCP tool. ```APIDOC ## GET /mcp/tools/:tool_name ### Description Retrieves detailed information about a specific MCP tool. ### Method GET ### Endpoint `/mcp/tools/:tool_name` ### Parameters #### Path Parameters - **tool_name** (string) - Required - The name of the tool to retrieve. ### Response #### Success Response (200) - **tool_schema** (object) - The schema definition for the specified tool, including its parameters and return types. #### Response Example ```json { "tool_schema": { "name": "calculator", "description": "Performs arithmetic operations.", "parameters": {"type": "object", "properties": {"operation": {"type": "string"}, "numbers": {"type": "array", "items": {"type": "number"}}}} } } ``` ``` -------------------------------- ### Get Specific MCP Prompt (GET) Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Retrieves details for a specific MCP prompt, including its template and required arguments. ```APIDOC ## GET /mcp/prompts/:prompt_name ### Description Retrieves details for a specific MCP prompt, including its template and required arguments. ### Method GET ### Endpoint `/mcp/prompts/:prompt_name` ### Parameters #### Path Parameters - **prompt_name** (string) - Required - The name of the prompt. #### Query Parameters - **arguments** (object) - Optional - Specific arguments to tailor the prompt details (e.g., version, style). ### Response #### Success Response (200) - **prompt_template** (string) - The template of the prompt. #### Response Example ```json { "prompt_template": "Review the following Ruby code for best practices: ```ruby {{ code }} ``` Focus on: {{ focus }}" } ``` ``` -------------------------------- ### List Items (GET) Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Lists items within a namespace, with support for prefix filtering, limit, and offset. ```APIDOC ## GET /store/namespace/:namespace ### Description Lists items within a namespace, with support for prefix filtering, limit, and offset. ### Method GET ### Endpoint `/store/namespace/:namespace` ### Parameters #### Path Parameters - **namespace** (string) - Required - The namespace to list items from. #### Query Parameters - **prefix** (string) - Optional - Filters items by a key prefix. - **limit** (integer) - Optional - Maximum number of items to return. - **offset** (integer) - Optional - Number of items to skip. ### Response #### Success Response (200) - **items** (array) - An array of item objects. - **key** (string) - The key of the item. - **value** (object) - The value of the item. - **namespace** (string) - The namespace of the item. #### Response Example ```json { "items": [ { "key": "user_1", "value": {"theme": "dark"}, "namespace": "user_preferences" }, { "key": "user_2", "value": {"theme": "light"}, "namespace": "user_preferences" } ] } ``` ``` -------------------------------- ### Get MCP Resource Metadata (GET) Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Retrieves metadata for a specific MCP resource identified by its URI. ```APIDOC ## GET /mcp/resources/:resource_uri ### Description Retrieves metadata for a specific MCP resource identified by its URI. ### Method GET ### Endpoint `/mcp/resources/:resource_uri` ### Parameters #### Path Parameters - **resource_uri** (string) - Required - The URI of the resource. ### Response #### Success Response (200) - **resource_metadata** (object) - Metadata associated with the resource. - **uri** (string) - The resource's URI. - **name** (string) - The resource's name. - **mime_type** (string) - The resource's MIME type. - **size** (integer) - The size of the resource in bytes. - **created_at** (string) - Timestamp of resource creation. #### Response Example ```json { "resource_metadata": { "uri": "resource://documents/readme", "name": "README.md", "mime_type": "text/markdown", "size": 1024, "created_at": "2023-10-27T10:00:00Z" } } ``` ``` -------------------------------- ### Create Multiple Runs in Batch Source: https://context7.com/gysmuller/langgraph-platform/llms.txt This example shows how to create multiple runs concurrently using a batch request. It defines a list of run configurations, each with an assistant ID, thread ID, and input messages, and then processes the results of the batch creation. ```ruby # Create multiple runs in batch batch_runs = [ { assistant_id: 'assistant-id-here', thread_id: 'thread-1', input: { messages: [{ role: 'user', content: 'Query 1' }] } }, { assistant_id: 'assistant-id-here', thread_id: 'thread-2', input: { messages: [{ role: 'user', content: 'Query 2' }] } }, { assistant_id: 'assistant-id-here', thread_id: 'thread-3', input: { messages: [{ role: 'user', content: 'Query 3' }] } } ] results = client.runs.create_batch(batch_runs) results.each do |run| puts "Created run: #{run['run_id']} on thread #{run['thread_id']}" end ``` -------------------------------- ### Perform Batch Operations on Data in LangGraph Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Demonstrates batch operations for getting, putting, and deleting multiple data items efficiently using the client.store API. This is useful for performing bulk data management tasks. ```ruby # Batch get multiple items items = client.store.batch_get( items: [ { namespace: 'user_preferences', key: 'user-123' }, { namespace: 'user_preferences', key: 'user-456' }, { namespace: 'settings', key: 'app-config' } ] ) items.each do |item| puts "Retrieved: #{item.namespace}/#{item.key}" end # Batch put multiple items results = client.store.batch_put( items: [ { namespace: 'cache', key: 'result-1', value: { data: 'cached_value_1' } }, { namespace: 'cache', key: 'result-2', value: { data: 'cached_value_2' } } ] ) # Batch delete multiple items client.store.batch_delete( items: [ { namespace: 'cache', key: 'result-1' }, { namespace: 'cache', key: 'result-2' } ] ) puts "Batch operations completed" ``` -------------------------------- ### Batch Get Items (POST) Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Retrieves multiple items from the store in a single request. ```APIDOC ## POST /store/batch_get ### Description Retrieves multiple items from the store in a single request. ### Method POST ### Endpoint `/store/batch_get` ### Parameters #### Request Body - **items** (array) - Required - An array of objects, each specifying a namespace and key to retrieve. - **namespace** (string) - Required - The namespace of the item. - **key** (string) - Required - The key of the item. ### Response #### Success Response (200) - **items** (array) - An array of retrieved item objects. - **key** (string) - The key of the item. - **value** (object) - The value of the item. - **namespace** (string) - The namespace of the item. #### Response Example ```json { "items": [ { "namespace": "user_preferences", "key": "user-123", "value": {"theme": "dark"} }, { "namespace": "settings", "key": "app-config", "value": {"timeout": 30} } ] } ``` ``` -------------------------------- ### Langgraph API Error Handling with Exceptions (Ruby) Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md Provides an example of robust error handling using begin-rescue blocks to catch specific LanggraphPlatform::Errors. This includes handling not found, unauthorized, and general API errors, with specific error classes listed for different HTTP status codes. ```ruby begin assistant = client.assistants.find('nonexistent-id') rescue LanggraphPlatform::Errors::NotFoundError => e puts "Assistant not found: #{e.message}" rescue LanggraphPlatform::Errors::UnauthorizedError => e puts "Authentication failed: #{e.message}" rescue LanggraphPlatform::Errors::APIError => e puts "API error: #{e.message}" end ``` -------------------------------- ### Create a Cron Job for Scheduled Tasks Source: https://context7.com/gysmuller/langgraph-platform/llms.txt This example shows how to create a cron job for scheduling periodic tasks. It includes specifying the assistant, a cron schedule, a payload for the task, an optional thread ID, and metadata for organization. ```ruby # Create a cron job cron = client.crons.create( assistant_id: 'assistant-id-here', schedule: '0 */6 * * *', # Every 6 hours payload: { task: 'data_sync', parameters: { source: 'database', destination: 'warehouse' } }, thread_id: 'thread-id-here', # Optional: use specific thread metadata: { department: 'data-engineering', priority: 'high' } ) puts "Cron ID: #{cron.cron_id}" puts "Schedule: #{cron.schedule}" puts "Status: #{cron.status}" # Create daily morning report cron morning_report = client.crons.create( assistant_id: 'report-assistant', schedule: '0 8 * * *', # Daily at 8 AM payload: { report_type: 'daily_summary' } ) ``` -------------------------------- ### Advanced Run Streaming with Multiple Modes and Webhooks Source: https://context7.com/gysmuller/langgraph-platform/llms.txt This example shows advanced run streaming using multiple stream modes ('updates', 'messages') and integrating a webhook for real-time notifications. It handles different event types like graph node updates and message partials, including error handling. ```ruby # Stream with multiple modes for full visibility client.runs.stream( 'thread-id-here', assistant_id: 'assistant-id-here', input: { messages: [{ role: 'user', content: 'Execute complex workflow' }] }, stream_mode: ['updates', 'messages'], webhook: 'https://your-app.com/webhooks/stream' ) do |type, data, id, reconnection_time| case type when 'updates' puts "Graph node executed: #{data.keys.first}" when 'messages/partial' print data.first['content'] if data.is_a?(Array) when 'error' puts "Error: #{data}" end end ``` -------------------------------- ### Update, Enable, Disable, and Delete Cron Jobs Source: https://context7.com/gysmuller/langgraph-platform/llms.txt This example covers the management of existing cron jobs, including updating their schedule and payload, enabling or disabling them, and deleting them entirely. These operations are essential for maintaining scheduled tasks. ```ruby # Update cron job updated = client.crons.update( 'cron-id-here', schedule: '0 */12 * * *', # Change to every 12 hours payload: { task: 'updated_sync' } ) # Enable/disable cron jobs client.crons.enable('cron-id-here') puts "Cron enabled" client.crons.disable('cron-id-here') puts "Cron disabled" # Delete cron job client.crons.delete('cron-id-here') puts "Cron deleted" ``` -------------------------------- ### Monitor, List, Cancel, and Delete Runs using Ruby LangGraph client Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Provides examples for finding a specific run, listing runs for a thread, cancelling an ongoing run with optional interrupt or rollback, and deleting a run. Requires run and thread identifiers. Outputs run status and confirmation messages. ```Ruby # Find a specific run run = client.runs.find('thread-id-here', 'run-id-here') puts \"Run status: #{run.status}\" puts \"Multitask strategy: #{run.multitask_strategy}\" # List all runs for a thread runs = client.runs.list( 'thread-id-here', limit: 10, offset: 0 ) runs.each do |r| puts \"Run #{r.run_id}: #{r.status}\" puts \"Created: #{r.created_at}\" end # Cancel a running execution client.runs.cancel( 'thread-id-here', 'run-id-here', wait: true, # Wait for cancellation to complete action: 'interrupt' # or 'rollback' ) puts \"Run cancelled\" # Delete a run client.runs.delete('thread-id-here', 'run-id-here') puts \"Run deleted\" ``` -------------------------------- ### Handle Langgraph Platform API Errors in Ruby Source: https://context7.com/gysmuller/langgraph-platform/llms.txt This snippet demonstrates how to handle various API errors raised by the langgraph_platform gem in Ruby. It covers specific exceptions like UnauthorizedError, NotFoundError, ValidationError, ConflictError, BadRequestError, and ServerError, along with a generic APIError and StandardError. Each rescue block provides example logging and comments for potential handling strategies. ```ruby require 'langgraph_platform' client = LanggraphPlatform::Client.new( api_key: 'fake-api-key', base_url: 'http://127.0.0.1:2024' ) begin # Attempt to find non-existent assistant assistant = client.assistants.find('nonexistent-id') rescue LanggraphPlatform::Errors::UnauthorizedError => e puts "Authentication failed: #{e.message}" puts "Status code: #{e.status_code}" # Handle: Check API key, refresh credentials rescue LanggraphPlatform::Errors::NotFoundError => e puts "Resource not found: #{e.message}" puts "Status code: #{e.status_code}" # Handle: Create resource or use different ID rescue LanggraphPlatform::Errors::ValidationError => e puts "Validation failed: #{e.message}" puts "Status code: #{e.status_code}" # Handle: Fix request parameters rescue LanggraphPlatform::Errors::ConflictError => e puts "Conflict detected: #{e.message}" puts "Status code: #{e.status_code}" # Handle: Resolve conflicts, retry with different data rescue LanggraphPlatform::Errors::BadRequestError => e puts "Bad request: #{e.message}" puts "Status code: #{e.status_code}" # Handle: Review and fix request format rescue LanggraphPlatform::Errors::ServerError => e puts "Server error: #{e.message}" puts "Status code: #{e.status_code}" # Handle: Retry with exponential backoff rescue LanggraphPlatform::Errors::APIError => e puts "API error: #{e.message}" puts "Status code: #{e.status_code}" # Handle: Generic error handling rescue StandardError => e puts "Unexpected error: #{e.class} - #{e.message}" puts e.backtrace.first(5).join("\n") # Handle: Log and alert end ``` -------------------------------- ### Initialize LangGraph Platform Ruby Client Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Demonstrates how to initialize and configure the LangGraph Platform client. Supports basic initialization with an API key, configuration for local development, advanced settings like timeouts and retries, and post-initialization configuration. ```ruby require 'langgraph_platform' # Basic initialization with API key client = LanggraphPlatform::Client.new( api_key: 'your-api-key-here', base_url: 'https://api.langchain.com' ) # For local development client = LanggraphPlatform::Client.new( api_key: 'fake-api-key', base_url: 'http://127.0.0.1:2024' ) # Advanced configuration with custom settings client = LanggraphPlatform::Client.new( api_key: ENV['LANGGRAPH_API_KEY'], base_url: 'https://custom-api.example.com', timeout: 60, retries: 5, user_agent: 'MyApp/1.0' ) # Configure after initialization client.configure do |config| config.timeout = 120 config.retries = 3 end ``` -------------------------------- ### Configure LangGraph Platform Ruby SDK Client Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md Demonstrates how to configure the LangGraph Platform Ruby SDK client, both during initialization and after. It covers API key, base URL, timeout, and retries settings. ```ruby client = LanggraphPlatform::Client.new( api_key: 'your-api-key', base_url: 'https://custom-api.example.com', timeout: 30, retries: 3 ) # Or configure after initialization client.configure do |config| config.timeout = 60 config.retries = 5 end ``` -------------------------------- ### List and Execute MCP Tools Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Shows how to interact with Model Context Protocol (MCP) tools, including listing available tools, retrieving specific tool details, and calling tools with arguments. This enables programmatic access to tool functionalities. ```ruby # List all available tools tools = client.mcp.list_tools tools.each do |tool| puts "Tool: #{tool['name']}" puts "Description: #{tool['description']}" puts "Parameters: #{tool['parameters']}" end # Get specific tool details tool = client.mcp.get_tool('calculator') puts "Tool schema: #{tool}" # Call a tool result = client.mcp.call_tool( name: 'calculator', arguments: { operation: 'add', numbers: [10, 20, 30] } ) puts "Tool result: #{result}" # Call web search tool search_result = client.mcp.call_tool( name: 'web_search', arguments: { query: 'Ruby programming best practices', num_results: 5 } ) puts "Search results: #{search_result}" ``` -------------------------------- ### Create LangGraph Platform Assistant Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Shows how to create a new AI assistant using the LangGraph Platform Ruby SDK. Includes basic configuration, specifying the graph ID, name, description, and advanced settings like recursion limits and metadata. ```ruby require 'langgraph_platform' client = LanggraphPlatform::Client.new( api_key: 'fake-api-key', base_url: 'http://127.0.0.1:2024' ) # Create assistant with basic configuration assistant = client.assistants.create( graph_id: 'chat', name: 'Customer Support Assistant', description: 'Handles customer inquiries and support tickets', config: { recursion_limit: 10, max_tokens: 1000 }, metadata: { department: 'support', version: '1.0', created_by: 'admin' } ) puts "Assistant ID: #{assistant.assistant_id}" puts "Name: #{assistant.name}" puts "Graph ID: #{assistant.graph_id}" puts "Config: #{assistant.config}" puts "Metadata: #{assistant.metadata}" ``` -------------------------------- ### Read MCP Resource Content (GET) Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Reads the content of a specific MCP resource identified by its URI. ```APIDOC ## GET /mcp/resources/:resource_uri/content ### Description Reads the content of a specific MCP resource identified by its URI. ### Method GET ### Endpoint `/mcp/resources/:resource_uri/content` ### Parameters #### Path Parameters - **resource_uri** (string) - Required - The URI of the resource. ### Response #### Success Response (200) - **content** (string) - The content of the resource. - **mime_type** (string) - The MIME type of the resource content. #### Response Example ```json { "contents": "# LangGraph Platform\nThis is the README file.", "mime_type": "text/markdown" } ``` ``` -------------------------------- ### List and Read MCP Resources Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Demonstrates how to list all available resources, retrieve resource metadata, and read the content of resources using the MCP client. This is essential for accessing and managing external data or configurations. ```ruby # List all available resources resources = client.mcp.list_resources resources.each do |resource| puts "Resource URI: #{resource['uri']}" puts "Name: #{resource['name']}" puts "MIME type: #{resource['mime_type']}" end # Get resource metadata resource = client.mcp.get_resource( uri: 'resource://documents/readme' ) puts "Resource metadata: #{resource}" # Read resource content content = client.mcp.read_resource( uri: 'resource://documents/readme' ) puts "Content: #{content['contents']}" puts "MIME type: #{content['mime_type']}" ``` -------------------------------- ### Manage Runs with LangGraph Platform Ruby SDK Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md Demonstrates how to manage runs using the LangGraph Platform Ruby SDK. Includes creating runs, with and without webhooks, streaming run events, waiting for runs to complete, listing runs, and cancelling runs. ```ruby # Create a run run = client.runs.create( thread.thread_id, assistant_id: assistant.assistant_id, input: { message: 'Hello!' } ) # Create a run with webhook run = client.runs.create( thread.thread_id, assistant_id: assistant.assistant_id, input: { message: 'Hello!' }, webhook: 'https://your-app.com/webhooks/langgraph' ) # Stream a run client.runs.stream( thread.thread_id, assistant_id: assistant.assistant_id, input: { message: 'Hello!' } ) do |type, data, id, reconnection_time| puts "Event: #{type}, Data: #{data}" end # Stream a run with webhook client.runs.stream( thread.thread_id, assistant_id: assistant.assistant_id, input: { message: 'Hello!' }, webhook: 'https://your-app.com/webhooks/langgraph' ) do |type, data, id, reconnection_time| puts "Event: #{type}, Data: #{data}" end # Wait for a run to complete result = client.runs.wait( thread.thread_id, assistant_id: assistant.assistant_id, input: { message: 'Hello!' } ) # Wait for a run with webhook result = client.runs.wait( thread.thread_id, assistant_id: assistant.assistant_id, input: { message: 'Hello!' }, webhook: 'https://your-app.com/webhooks/langgraph' ) # List runs runs = client.runs.list(thread.thread_id) # Cancel a run client.runs.cancel(thread.thread_id, run.run_id) ``` -------------------------------- ### Manage LangGraph Platform Assistant Versions Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Shows how to retrieve all deployed versions of an assistant and how to set a specific version as the latest, useful for managing deployments and rollbacks. ```ruby # Get all versions of an assistant versions = client.assistants.versions('assistant-id-here') versions.each do |version| puts "Version: #{version.version} - #{version.name}" puts "Created: #{version.created_at}" end # Set a specific version as latest latest = client.assistants.set_latest_version( 'assistant-id-here', version: 3 ) puts "Latest version now: #{latest.version}" ``` -------------------------------- ### Langgraph Model Context Protocol (MCP) Operations (Ruby) Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md Illustrates how to interact with the Model Context Protocol (MCP) to list available tools, call a specific tool with arguments, list resources, read resource content, and manage prompts. This is essential for leveraging AI models and their associated resources. ```ruby # List available tools tools = client.mcp.list_tools # Call a tool result = client.mcp.call_tool( 'tool_name', arguments: { param: 'value' } ) # List resources resources = client.mcp.list_resources # Read a resource content = client.mcp.read_resource('resource://example') # Work with prompts prompts = client.mcp.list_prompts result = client.mcp.complete_prompt('prompt_name', arguments: {}) ``` -------------------------------- ### Running Project Tests and Linters (Bash) Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md Shows the bash commands necessary for running the project's tests using RSpec and for performing code linting with RuboCop. These commands are essential for development and maintaining code quality. ```bash $ bundle exec rspec $ bundle exec rubocop ``` -------------------------------- ### Complete MCP Prompt (POST) Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Submits arguments to an MCP prompt and receives a completion. ```APIDOC ## POST /mcp/prompts/complete ### Description Submits arguments to an MCP prompt and receives a completion. ### Method POST ### Endpoint `/mcp/prompts/complete` ### Parameters #### Request Body - **name** (string) - Required - The name of the prompt to complete. - **arguments** (object) - Required - The arguments to fill the prompt template. ### Response #### Success Response (200) - **messages** (array) - An array of messages representing the completion result. #### Response Example ```json { "messages": [ { "role": "assistant", "content": "The provided Ruby code is generally well-structured..." } ] } ``` ``` -------------------------------- ### Wait for Run Completion (blocking) and with Webhook using Ruby Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Shows how to block until a run finishes, retrieving final values, status, and checkpoint, and an alternative call that triggers a webhook upon completion. Requires assistant and thread IDs and appropriate input messages. ```Ruby # Wait for run to complete (blocking) result = client.runs.wait( 'thread-id-here', assistant_id: 'assistant-id-here', input: { messages: [ { role: 'user', content: 'Analyze this data and provide insights' } ] }, config: { recursion_limit: 20 } ) # Result contains the final state puts \"Final values: #{result['values']}\" puts \"Status: #{result['status']}\" puts \"Checkpoint: #{result['checkpoint']}\" # Wait with webhook result = client.runs.wait( 'thread-id-here', assistant_id: 'assistant-id-here', input: { messages: [{ role: 'user', content: 'Execute task' }] }, webhook: 'https://your-app.com/webhooks/complete' ) ``` -------------------------------- ### Get and Update Thread Conversation State with Ruby Source: https://context7.com/gysmuller/langgraph-platform/llms.txt Retrieves the current state of a thread, optionally including subgraph states, and updates the state with new values, node context, and checkpoint information. Requires thread ID and a LangGraph client. Outputs state details and confirmation of update. ```Ruby # Get current thread state state = client.threads.state( 'thread-id-here', subgraphs: false # Include subgraph states if true ) puts \"State values: #{state.values}\" puts \"Checkpoint: #{state.checkpoint}\" puts \"Next actions: #{state.next}\" puts \"Metadata: #{state.metadata}\" puts \"Created at: #{state.created_at}\" # Update thread state client.threads.update_state( 'thread-id-here', values: { messages: [], context: { user_preference: 'verbose' }, variables: { counter: 5 } }, as_node: 'agent', checkpoint: { thread_id: 'thread-id', checkpoint_ns: 'main' } ) puts \"State updated successfully\" ``` -------------------------------- ### Langgraph Store Operations (Ruby) Source: https://github.com/gysmuller/langgraph-platform/blob/main/README.md Demonstrates basic store operations including listing items with a prefix, deleting a specific key, and performing batch put operations. These functions are useful for managing data within namespaces. ```ruby items = client.store.list('namespace', prefix: 'user_') client.store.delete('namespace', 'key') client.store.batch_put([ { namespace: 'ns1', key: 'key1', value: 'value1' }, { namespace: 'ns1', key: 'key2', value: 'value2' } ]) ```