### WebSocket Command: Start Run Source: https://github.com/langchain-ai/agent-protocol/blob/main/streaming/README.md Example of a client-to-server command to start a run via WebSocket. Includes assistant ID and initial input messages. ```json { "id": 1, "method": "run.start", "params": { "assistantId": "agent", "input": { "messages": [{ "role": "user", "content": "Hello" }] } } } ``` -------------------------------- ### Install ap-client via Setuptools Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/README.md Install the ap-client package using Setuptools. Use `--user` for user-specific installation or `sudo` for system-wide installation. ```sh python setup.py install --user ``` -------------------------------- ### Install langchain-protocol Source: https://github.com/langchain-ai/agent-protocol/blob/main/streaming/py/README.md Install the package using pip. ```bash pip install langchain-protocol ``` -------------------------------- ### WebSocket Response: Successful Run Start Source: https://github.com/langchain-ai/agent-protocol/blob/main/streaming/README.md Example of a server-to-client successful response to a command, including the original command ID and the result (e.g., run ID). ```json { "type": "success", "id": 1, "result": { "runId": "run_123" }, "meta": { "appliedThroughSeq": 42 } } ``` -------------------------------- ### Get Agent using ap-client Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/README.md Example of how to instantiate the AgentsApi and retrieve an agent by its ID. Handles potential API exceptions. Ensure the host configuration is set correctly. ```python import ap_client from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) # Enter a context with an instance of the API client with ap_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = ap_client.AgentsApi(api_client) agent_id = 'agent_id_example' # str | The ID of the agent. try: # Get Agent api_response = api_instance.get_agent(agent_id) print("The response of AgentsApi->get_agent:\n") pprint(api_response) except ApiException as e: print("Exception when calling AgentsApi->get_agent: %s\n" % e) ``` -------------------------------- ### Define Subscription Parameters and Command Source: https://github.com/langchain-ai/agent-protocol/blob/main/streaming/py/README.md Example of defining subscription parameters and a subscription command using the provided types. ```python from langchain_protocol import Command, SubscribeParams params: SubscribeParams = { "channels": ["messages", "lifecycle"], } subscribe: Command = { "id": 1, "method": "subscription.subscribe", "params": params, } ``` -------------------------------- ### Install @langchain/protocol Source: https://github.com/langchain-ai/agent-protocol/blob/main/streaming/js/README.md Install the package using npm. This command is used to add the @langchain/protocol package to your project dependencies. ```bash npm install @langchain/protocol ``` -------------------------------- ### Install ap-client via pip Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/README.md Install the ap-client package directly from a Git repository using pip. You might need root permissions. ```sh pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git ``` -------------------------------- ### Hurl: Create Thread, Get Thread, Create Run, Wait for Output Source: https://github.com/langchain-ai/agent-protocol/blob/main/README.md Demonstrates the typical sequence of creating a thread, launching a run, and waiting for the final output. This pattern is common for multi-turn interactions. Use `GET /threads/{thread_id}/runs/{run_id}/stream` to stream output or `GET /threads/{thread_id}` to poll status. ```hurl # 1. Create a brand new thread POST http://localhost:8000/threads Content-Type: application/json { "thread_id": "229c1834-bc04-4d90-8fd6-77f6b9ef1462", "metadata": { "purpose": "support-chat" } } HTTP/1.1 200 [Asserts] jsonpath "$.thread_id" == "229c1834-bc04-4d90-8fd6-77f6b9ef1462" # 2. Retrieve the thread we just created GET http://localhost:8000/threads/229c1834-bc04-4d90-8fd6-77f6b9ef1462 HTTP/1.1 200 [Asserts] jsonpath "$.status" == "idle" # 3. Create a run in the existing thread (background run). # Capture the run_id for the next step. POST http://localhost:8000/threads/229c1834-bc04-4d90-8fd6-77f6b9ef1462/runs Content-Type: application/json { "input": { "message": "Hi there, what's the weather?" }, "metadata": { "requestType": "weatherQuery" } } HTTP/1.1 200 [Captures] run_id: jsonpath "$.run_id" [Asserts] jsonpath "$.status" == "pending" # 4. Wait for final run output GET http://localhost:8000/threads/229c1834-bc04-4d90-8fd6-77f6b9ef1462/runs/{{run_id}}/wait HTTP/1.1 200 [Asserts] # For example, check that the run status is success or error, # depending on your actual system's response: jsonpath "$.status" == "success" ``` -------------------------------- ### ThreadState Usage Example Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/ThreadState.md Example of how to use the ThreadState model in Python. ```APIDOC ## ThreadState Example ### Description Example of how to use the ThreadState model in Python. ### Request Example ```python from ap_client.models.thread_state import ThreadState # TODO update the JSON string below json = "{}" # create an instance of ThreadState from a JSON string thread_state_instance = ThreadState.from_json(json) # print the JSON string representation of the object print(ThreadState.to_json()) # convert the object into a dict thread_state_dict = thread_state_instance.to_dict() # create an instance of ThreadState from a dict thread_state_from_dict = ThreadState.from_dict(thread_state_dict) ``` ``` -------------------------------- ### Import ap-client after pip installation Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/README.md Import the ap-client package into your Python script after installing it via pip. ```python import ap_client ``` -------------------------------- ### GET /store/items Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/StoreApi.md Retrieves a specific item from the store using its key and an optional namespace. ```APIDOC ## GET /store/items ### Description Get Store Item ### Method GET ### Endpoint /store/items ### Parameters #### Query Parameters - **key** (str) - Required - The key of the item to retrieve. - **namespace** (List[str]) - Optional - A list of namespaces to search within. ### Request Example ```json { "example": "request body" } ``` ### Response #### Success Response (200) - **Item** (Item) - The retrieved item object. #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Search Runs using Python Client Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/BackgroundRunsApi.md Search for runs based on criteria like thread, agent, or status. This example shows how to initiate a search with a `RunSearchRequest` object. ```python import ap_client from ap_client.models.run import Run from ap_client.models.run_search_request import RunSearchRequest from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) # Enter a context with an instance of the API client with ap_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = ap_client.BackgroundRunsApi(api_client) run_search_request = ap_client.RunSearchRequest() # RunSearchRequest | try: # Search Runs api_response = api_instance.search_runs(run_search_request) print("The response of BackgroundRunsApi->search_runs:\n") pprint(api_response) except Exception as e: print("Exception when calling BackgroundRunsApi->search_runs: %s\n" % e) ``` -------------------------------- ### Create and Stream Run Output Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/RunsApi.md Use this method to create a new run in a thread and stream its output as it becomes available. Ensure the ap_client library is installed and configured. ```python import ap_client from ap_client.models.run_stream import RunStream from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) # Enter a context with an instance of the API client with ap_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = ap_client.RunsApi(api_client) run_stream = ap_client.RunStream() # RunStream | try: # Create Run, Stream Output api_response = api_instance.create_and_stream_run(run_stream) print("The response of RunsApi->create_and_stream_run:\n") pprint(api_response) except Exception as e: print("Exception when calling RunsApi->create_and_stream_run: %s\n" % e) ``` -------------------------------- ### Content Block Finish: Tool Call Example Source: https://github.com/langchain-ai/agent-protocol/blob/main/streaming/README.md Finalizes a tool call content block. Provides the complete, parsed tool call arguments. ```json { "event": "content-block-finish", "index": 1, "content": { "type": "tool_call", "id": "call_123", "name": "search", "args": { "query": "weather" } } } ``` -------------------------------- ### Search Threads using Python Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/ThreadsApi.md This Python snippet demonstrates how to search for threads using the ap_client library. It can also be used to list all threads by providing an empty search request. Ensure the ap_client library is installed and configured. ```python import ap_client from ap_client.models.thread import Thread from ap_client.models.thread_search_request import ThreadSearchRequest from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) # Enter a context with an instance of the API client with ap_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = ap_client.ThreadsApi(api_client) thread_search_request = ap_client.ThreadSearchRequest() # ThreadSearchRequest | try: # Search Threads api_response = api_instance.search_threads(thread_search_request) print("The response of ThreadsApi->search_threads:\n") pprint(api_response) except Exception as e: print("Exception when calling ThreadsApi->search_threads: %s\n" % e) ``` -------------------------------- ### WebSocket Response: Event Source: https://github.com/langchain-ai/agent-protocol/blob/main/streaming/README.md Example of an unsolicited server-sent event over WebSocket. Includes event ID, sequence number, method, and event parameters. ```json { "type": "event", "eventId": "evt_123", "seq": 43, "method": "messages", "params": { "namespace": [], "timestamp": 1710000000000, "data": { "event": "message-start", "role": "ai", "id": "msg_123" } } } ``` -------------------------------- ### Content Block Delta: Tool Call Chunk Example Source: https://github.com/langchain-ai/agent-protocol/blob/main/streaming/README.md Streams partial tool call arguments. Uses 'block-delta' to incrementally build tool call arguments. ```json { "event": "content-block-delta", "index": 1, "delta": { "type": "block-delta", "fields": { "type": "tool_call_chunk", "id": "call_123", "name": "search", "args": "{\"query\":" } } } ``` -------------------------------- ### Copy Thread using ThreadsApi Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/ThreadsApi.md Use this method to create a new thread by copying the state and checkpoints from an existing thread. Ensure the ap_client library is installed and configured. ```python import ap_client from ap_client.models.thread import Thread from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) # Enter a context with an instance of the API client with ap_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = ap_client.ThreadsApi(api_client) thread_id = 'thread_id_example' # str | The ID of the thread. try: # Copy Thread api_response = api_instance.copy_thread(thread_id) print("The response of ThreadsApi->copy_thread:\n") pprint(api_response) except Exception as e: print("Exception when calling ThreadsApi->copy_thread: %s\n" % e) ``` -------------------------------- ### Create and Wait for Run Output Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/RunsApi.md This method creates a run in a new thread and waits for its completion, returning the final output. It's suitable when you need the result before proceeding. Ensure the ap_client library is installed and configured. ```python import ap_client from ap_client.models.run_create import RunCreate from ap_client.models.run_wait_response import RunWaitResponse from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) # Enter a context with an instance of the API client with ap_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = ap_client.RunsApi(api_client) run_create = ap_client.RunCreate() # RunCreate | try: # Create Run, Wait for Output api_response = api_instance.create_and_wait_run(run_create) print("The response of RunsApi->create_and_wait_run:\n") pprint(api_response) except Exception as e: print("Exception when calling RunsApi->create_and_wait_run: %s\n" % e) ``` -------------------------------- ### Create and Use Input Instance Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/Input.md Demonstrates creating an Input instance from a JSON string and converting it to a dictionary. Ensure the JSON string is valid. ```python from ap_client.models.input import Input # TODO update the JSON string below json = "{}" # create an instance of Input from a JSON string input_instance = Input.from_json(json) # print the JSON string representation of the object print(Input.to_json()) # convert the object into a dict input_dict = input_instance.to_dict() # create an instance of Input from a dict input_from_dict = Input.from_dict(input_dict) ``` -------------------------------- ### Instantiate RunCreate from JSON and Dict Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/RunCreate.md Demonstrates how to create a RunCreate object from a JSON string or a dictionary, and how to convert it back to JSON or a dictionary. Ensure the JSON string is valid. ```python from ap_client.models.run_create import RunCreate # TODO update the JSON string below json = "{}" # create an instance of RunCreate from a JSON string run_create_instance = RunCreate.from_json(json) # print the JSON string representation of the object print(RunCreate.to_json()) # convert the object into a dict run_create_dict = run_create_instance.to_dict() # create an instance of RunCreate from a dict run_create_from_dict = RunCreate.from_dict(run_create_dict) ``` -------------------------------- ### GET /threads/{thread_id} - Get Thread Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/ThreadsApi.md Retrieves a specific thread by its ID. ```APIDOC ## GET /threads/{thread_id} ### Description Get a thread by ID. ### Method GET ### Endpoint /threads/{thread_id} ### Parameters #### Path Parameters - **thread_id** (str) - Required - The ID of the thread. ### Response #### Success Response (200) - **Thread** (Thread) - Details of the requested thread. #### Error Response - **404** - Not Found - **422** - Validation Error ``` -------------------------------- ### List Namespaces using Store API Client Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/StoreApi.md Demonstrates how to list available namespaces using the StoreApi client. Ensure the ApiClient is configured with the correct host. ```python import ap_client from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) # Enter a context with an instance of the API client with ap_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = ap_client.StoreApi(api_client) store_list_namespaces_request = ap_client.StoreListNamespacesRequest() # StoreListNamespacesRequest | try: # List namespaces api_response = api_instance.list_namespaces(store_list_namespaces_request) print("The response of StoreApi->list_namespaces:\n") pprint(api_response) except Exception as e: print("Exception when calling StoreApi->list_namespaces: %s\n" % e) ``` -------------------------------- ### Python Config Object Instantiation and Conversion Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/Config.md Demonstrates how to create a Config object from a JSON string, convert it to a dictionary, and create a new object from a dictionary. Ensure the JSON string is valid. ```python from ap_client.models.config import Config # TODO update the JSON string below json = "{}" # create an instance of Config from a JSON string config_instance = Config.from_json(json) # print the JSON string representation of the object print(Config.to_json()) # convert the object into a dict config_dict = config_instance.to_dict() # create an instance of Config from a dict config_from_dict = Config.from_dict(config_dict) ``` -------------------------------- ### GET /runs/{run_id} - Get Run Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/BackgroundRunsApi.md Retrieves the details of a specific background run. ```APIDOC ## GET /runs/{run__id} ### Description Retrieves the details of a specific background run. ### Method GET ### Endpoint /runs/{run_id} ### Parameters #### Path Parameters - **run_id** (str) - Required - The ID of the run to retrieve. ### Response #### Success Response (200) - **Run** (Run) - An object containing details of the run. #### Response Example ```json { "id": "run_id_123", "name": "Weather Agent", "start_time": "2023-10-27T10:00:00Z", "end_time": "2023-10-27T10:05:00Z", "status": "completed", "output": "The weather today is sunny." } ``` #### Error Response - **404** - Not Found ``` -------------------------------- ### Instantiate and Convert Run Object Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/Run.md Demonstrates how to create a Run instance from a JSON string, convert it to a dictionary, and create a Run instance from a dictionary. Ensure the JSON string is valid and contains the expected structure for the Run model. ```python from ap_client.models.run import Run # TODO update the JSON string below json = "{}" # create an instance of Run from a JSON string run_instance = Run.from_json(json) # print the JSON string representation of the object print(Run.to_json()) # convert the object into a dict run_dict = run_instance.to_dict() # create an instance of Run from a dict run_from_dict = Run.from_dict(run_dict) ``` -------------------------------- ### GET /threads/{thread_id}/history - Get Thread History Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/ThreadsApi.md Retrieves the history of messages within a specific thread. ```APIDOC ## GET /threads/{thread_id}/history ### Description Get the history of messages in a thread. ### Method GET ### Endpoint /threads/{thread_id}/history ### Parameters #### Path Parameters - **thread_id** (str) - Required - The ID of the thread. ### Response #### Success Response (200) - **list[Message]** - A list of messages in the thread's history. #### Error Response - **404** - Not Found - **422** - Validation Error ``` -------------------------------- ### AgentSchema Instance Creation and Conversion Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/AgentSchema.md Demonstrates how to create an AgentSchema instance from a JSON string and convert it to a dictionary. Also shows how to create an instance from a dictionary and print its JSON representation. Ensure the JSON string is valid. ```python from ap_client.models.agent_schema import AgentSchema # TODO update the JSON string below json = "{}" # create an instance of AgentSchema from a JSON string agent_schema_instance = AgentSchema.from_json(json) # print the JSON string representation of the object print(AgentSchema.to_json()) # convert the object into a dict agent_schema_dict = agent_schema_instance.to_dict() # create an instance of AgentSchema from a dict agent_schema_from_dict = AgentSchema.from_dict(agent_schema_dict) ``` -------------------------------- ### Create and Manipulate Agent Instance Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/Agent.md Demonstrates how to create an Agent instance from a JSON string, convert it to JSON, and convert it to a dictionary. Ensure the JSON string is valid and properly formatted. ```python from ap_client.models.agent import Agent # TODO update the JSON string below json = "{}" # create an instance of Agent from a JSON string agent_instance = Agent.from_json(json) # print the JSON string representation of the object print(Agent.to_json()) # convert the object into a dict agent_dict = agent_instance.to_dict() # create an instance of Agent from a dict agent_from_dict = Agent.from_dict(agent_dict) ``` -------------------------------- ### GET /runs/{run_id} Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/BackgroundRunsApi.md Retrieves a specific run by its unique identifier. ```APIDOC ## GET /runs/{run_id} ### Description Get a run by ID. ### Method GET ### Endpoint /runs/{run_id} ### Parameters #### Path Parameters - **run_id** (str) - Required - The ID of the run. ### Return type [**Run**](Run.md) ### Request Example ```python import ap_client from ap_client.models.run import Run from ap_client.rest import ApiException from pprint import pprint configuration = ap_client.Configuration( host = "http://localhost" ) with ap_client.ApiClient(configuration) as api_client: api_instance = ap_client.BackgroundRunsApi(api_client) run_id = 'run_id_example' try: api_response = api_instance.get_run(run_id) print("The response of BackgroundRunsApi->get_run:\n") pprint(api_response) except Exception as e: print("Exception when calling BackgroundRunsApi->get_run: %s\n" % e) ``` ### Response #### Success Response (200) - **run** (Run) - Details of the requested run. #### Response Example ```json { "example": "response body" } ``` #### Error Response (404) - Not Found #### Error Response (422) - Validation Error ``` -------------------------------- ### Instantiate and Convert Content Model Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/Content.md Demonstrates creating a Content instance from a JSON string, converting it to a dictionary, and creating a new instance from that dictionary. Requires the `Content` model from `ap_client.models.content`. ```python from ap_client.models.content import Content # TODO update the JSON string below json = "{}" # create an instance of Content from a JSON string content_instance = Content.from_json(json) # print the JSON string representation of the object print(Content.to_json()) # convert the object into a dict content_dict = content_instance.to_dict() # create an instance of Content from a dict content_from_dict = Content.from_dict(content_dict) ``` -------------------------------- ### GET /agents/{agent_id} Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/AgentsApi.md Retrieves a specific agent by its unique identifier. ```APIDOC ## GET /agents/{agent_id} ### Description Get an agent by ID. ### Method GET ### Endpoint /agents/{agent_id} ### Parameters #### Path Parameters - **agent_id** (str) - Required - The ID of the agent. ### Response #### Success Response (200) - **Agent** (Agent) - Description of the Agent model #### Error Response - **404** - Not Found ``` -------------------------------- ### GET /agents/{agent_id}/schemas Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/AgentsApi.md Retrieves the schemas associated with a specific agent. ```APIDOC ## GET /agents/{agent_id}/schemas ### Description Get an agent's schemas by ID. ### Method GET ### Endpoint /agents/{agent_id}/schemas ### Parameters #### Path Parameters - **agent_id** (str) - Required - The ID of the agent. ### Response #### Success Response (200) - **AgentSchema** (AgentSchema) - Description of the AgentSchema model #### Error Response - **404** - Not Found - **422** - Validation Error ``` -------------------------------- ### Instantiate and Convert RunWaitResponse Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/RunWaitResponse.md Demonstrates creating a RunWaitResponse instance from a JSON string and converting it to a dictionary. Also shows converting a dictionary back to a RunWaitResponse instance. Ensure the JSON string is valid. ```python from ap_client.models.run_wait_response import RunWaitResponse # TODO update the JSON string below json = "{}" # create an instance of RunWaitResponse from a JSON string run_wait_response_instance = RunWaitResponse.from_json(json) # print the JSON string representation of the object print(RunWaitResponse.to_json()) # convert the object into a dict run_wait_response_dict = run_wait_response_instance.to_dict() # create an instance of RunWaitResponse from a dict run_wait_response_from_dict = RunWaitResponse.from_dict(run_wait_response_dict) ``` -------------------------------- ### Get a memory item Source: https://github.com/langchain-ai/agent-protocol/blob/main/README.md Retrieves a single memory item using its namespace and key. ```APIDOC ## GET /store/items ### Description Retrieves a single memory item using its namespace and key. ### Method GET ### Endpoint /store/items ### Parameters #### Path Parameters - **namespace** (string) - Required - The namespace for the memory item. - **key** (string) - Required - The key for the memory item. ### Response #### Success Response (200) - **content** (string) - The content of the memory item. ``` -------------------------------- ### Item Model Usage Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/Item.md Demonstrates creating an Item instance from a JSON string, converting it to JSON, converting it to a dictionary, and creating an Item instance from a dictionary. Ensure the JSON string is valid. ```python from ap_client.models.item import Item # TODO update the JSON string below json = "{}" # create an instance of Item from a JSON string item_instance = Item.from_json(json) # print the JSON string representation of the object print(Item.to_json()) # convert the object into a dict item_dict = item_instance.to_dict() # create an instance of Item from a dict item_from_dict = Item.from_dict(item_dict) ``` -------------------------------- ### GET /threads/{thread_id}/runs Source: https://github.com/langchain-ai/agent-protocol/blob/main/README.md Lists all background runs associated with a specific thread. ```APIDOC ## GET /threads/{thread_id}/runs ### Description List runs for a thread. ### Method GET ### Endpoint /threads/{thread_id}/runs ### Parameters #### Path Parameters - **thread_id** (string) - Required - The unique identifier of the thread. ### Response #### Success Response (200) - **runs** (array) - A list of run objects. #### Response Example ```json { "runs": [ { "id": "run_abc", "thread_id": "thread_xyz", "status": "completed", "created_at": "2023-10-27T10:00:00Z", "completed_at": "2023-10-27T10:05:00Z" } ] } ``` ``` -------------------------------- ### Create and Convert SearchAgentsRequest Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/SearchAgentsRequest.md Demonstrates how to create a SearchAgentsRequest instance from a JSON string, convert it to a dictionary, and create a new instance from that dictionary. Ensure the JSON string is valid. ```python from ap_client.models.search_agents_request import SearchAgentsRequest # TODO update the JSON string below json = "{}" # create an instance of SearchAgentsRequest from a JSON string search_agents_request_instance = SearchAgentsRequest.from_json(json) # print the JSON string representation of the object print(SearchAgentsRequest.to_json()) # convert the object into a dict search_agents_request_dict = search_agents_request_instance.to_dict() # create an instance of SearchAgentsRequest from a dict search_agents_request_from_dict = SearchAgentsRequest.from_dict(search_agents_request_dict) ``` -------------------------------- ### Instantiate and Convert StoreSearchRequest Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/StoreSearchRequest.md Demonstrates how to create a StoreSearchRequest instance from a JSON string or a dictionary, and how to convert it back to a dictionary or JSON string. Ensure the JSON string is valid before parsing. ```python from ap_client.models.store_search_request import StoreSearchRequest # TODO update the JSON string below json = "{}" # create an instance of StoreSearchRequest from a JSON string store_search_request_instance = StoreSearchRequest.from_json(json) # print the JSON string representation of the object print(StoreSearchRequest.to_json()) # convert the object into a dict store_search_request_dict = store_search_request_instance.to_dict() # create an instance of StoreSearchRequest from a dict store_search_request_from_dict = StoreSearchRequest.from_dict(store_search_request_dict) ``` -------------------------------- ### GET /runs/{run_id}/wait - Wait for Run output Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/BackgroundRunsApi.md Waits for the output of a specific background run to be available. ```APIDOC ## GET /runs/{run_id}/wait ### Description Waits for the output of a specific background run to be available. This endpoint is useful when you need to ensure a run has completed before proceeding. ### Method GET ### Endpoint /runs/{run_id}/wait ### Parameters #### Path Parameters - **run_id** (str) - Required - The ID of the run to wait for. ### Response #### Success Response (200) - **Run** (Run) - An object containing the details of the completed run, including its final output. #### Response Example ```json { "id": "run_id_123", "name": "Weather Agent", "start_time": "2023-10-27T10:00:00Z", "end_time": "2023-10-27T10:05:00Z", "status": "completed", "output": "The weather today is sunny." } ``` #### Error Response - **404** - Not Found ``` -------------------------------- ### Create and Use StoreListNamespacesRequest Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/StoreListNamespacesRequest.md Demonstrates how to create an instance of StoreListNamespacesRequest from a JSON string, convert it to a dictionary, and create it from a dictionary. Assumes a JSON string is provided. ```python from ap_client.models.store_list_namespaces_request import StoreListNamespacesRequest # TODO update the JSON string below json = "{}" # create an instance of StoreListNamespacesRequest from a JSON string store_list_namespaces_request_instance = StoreListNamespacesRequest.from_json(json) # print the JSON string representation of the object print(StoreListNamespacesRequest.to_json()) # convert the object into a dict store_list_namespaces_request_dict = store_list_namespaces_request_instance.to_dict() # create an instance of StoreListNamespacesRequest from a dict store_list_namespaces_request_from_dict = StoreListNamespacesRequest.from_dict(store_list_namespaces_request_dict) ``` -------------------------------- ### GET /runs/{run_id}/stream - Stream output from Run Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/BackgroundRunsApi.md Streams the output from a specific background run in real-time. ```APIDOC ## GET /runs/{run_id}/stream ### Description Streams the output from a specific background run in real-time. This is useful for observing the progress and results of a long-running agent task. ### Method GET ### Endpoint /runs/{run_id}/stream ### Parameters #### Path Parameters - **run_id** (str) - Required - The ID of the run whose output to stream. ### Response #### Success Response (200) - **stream** (string) - A stream of output events from the run. #### Response Example ``` data: {"content": "Processing step 1..."}\n\n data: {"content": "Step 1 complete. Starting step 2..."}\n\n data: {"content": "Final output: Success!"}\n\n ``` -------------------------------- ### Search Agents using API Client Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/AgentsApi.md Initializes the API client and searches for agents. Handles potential exceptions during the API call. Requires the `ap_client` library to be configured. ```python with ap_client.ApiClient(configuration) as api_client: api_instance = ap_client.AgentsApi(api_client) search_agents_request = ap_client.SearchAgentsRequest() try: api_response = api_instance.search_agents(search_agents_request) print("The response of AgentsApi->search_agents:\n") pprint(api_response) except Exception as e: print("Exception when calling AgentsApi->search_agents: %s\n" % e) ``` -------------------------------- ### Delete Thread using ThreadsApi Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/ThreadsApi.md Use this method to delete a thread by its ID. Ensure the ap_client library is installed and configured. ```python import ap_client from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) ``` -------------------------------- ### Instantiate and Use AgentSchemas Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/AgentSchemas.md Demonstrates creating an AgentSchemas instance from a JSON string and converting it to/from a dictionary. Requires the ap_client library. ```python from ap_client.models.agent_schemas import AgentSchemas # TODO update the JSON string below json = "{}" # create an instance of AgentSchemas from a JSON string agent_schemas_instance = AgentSchemas.from_json(json) # print the JSON string representation of the object print(AgentSchemas.to_json()) # convert the object into a dict agent_schemas_dict = agent_schemas_instance.to_dict() # create an instance of AgentSchemas from a dict agent_schemas_from_dict = AgentSchemas.from_dict(agent_schemas_dict) ``` -------------------------------- ### Create and Use ErrorResponse Instance Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/ErrorResponse.md Demonstrates how to create an ErrorResponse instance from a JSON string, convert it to a dictionary, and create it from a dictionary. Ensure the JSON string is valid. ```python from ap_client.models.error_response import ErrorResponse # TODO update the JSON string below json = "{}" # create an instance of ErrorResponse from a JSON string error_response_instance = ErrorResponse.from_json(json) # print the JSON string representation of the object print(ErrorResponse.to_json()) # convert the object into a dict error_response_dict = error_response_instance.to_dict() # create an instance of ErrorResponse from a dict error_response_from_dict = ErrorResponse.from_dict(error_response_dict) ``` -------------------------------- ### GET /threads/{thread_id}/history Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/ThreadsApi.md Retrieves the history of a thread, including all past states. This is useful for reviewing the evolution of a conversation. ```APIDOC ## GET /threads/{thread_id}/history ### Description Get all past states for a thread. ### Method GET ### Endpoint /threads/{thread_id}/history ### Parameters #### Path Parameters - **thread_id** (str) - Required - The ID of the thread. #### Query Parameters - **limit** (int) - Optional - Limits the number of history entries returned. Defaults to 10. - **before** (str) - Optional - Returns history entries before a specific ID. ### Response #### Success Response (200) - **List[ThreadState]** - A list of past thread states. #### Response Example ```json { "example": "List of ThreadState objects" } ``` ``` -------------------------------- ### GET /threads/{thread_id} Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/ThreadsApi.md Retrieves a specific thread by its ID. This endpoint allows you to fetch the current state of a conversation thread. ```APIDOC ## GET /threads/{thread_id} ### Description Get a thread by ID. ### Method GET ### Endpoint /threads/{thread_id} ### Parameters #### Path Parameters - **thread_id** (str) - Required - The ID of the thread. ### Response #### Success Response (200) - **Thread** (Thread) - Description of the thread object. #### Response Example ```json { "example": "Thread object" } ``` #### Error Response - **404** - Not Found - **422** - Validation Error ``` -------------------------------- ### Delete Run using Python Client Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/BackgroundRunsApi.md Use this snippet to delete a specific run by its ID. Ensure the `ap_client` is installed and configured. ```python import ap_client from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) # Enter a context with an instance of the API client with ap_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = ap_client.BackgroundRunsApi(api_client) run_id = 'run_id_example' # str | The ID of the run. try: # Delete Run api_instance.delete_run(run_id) except Exception as e: print("Exception when calling BackgroundRunsApi->delete_run: %s\n" % e) ``` -------------------------------- ### POST /store/namespaces Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/StoreApi.md Lists available namespaces within the store. ```APIDOC ## POST /store/namespaces ### Description List namespaces ### Method POST ### Endpoint /store/namespaces ### Parameters #### Request Body - **store_list_namespaces_request** (StoreListNamespacesRequest) - Required - The request object for listing namespaces. ### Request Example ```json { "example": "request body" } ``` ### Response #### Success Response (200) - **List[List[str]]** - A list of namespaces. #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Get Run by ID using Python Client Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/BackgroundRunsApi.md Retrieve details of a specific run using its ID. This requires the `ap_client` to be set up. ```python import ap_client from ap_client.models.run import Run from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) # Enter a context with an instance of the API client with ap_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = ap_client.BackgroundRunsApi(api_client) run_id = 'run_id_example' # str | The ID of the run. try: # Get Run api_response = api_instance.get_run(run_id) print("The response of BackgroundRunsApi->get_run:\n") pprint(api_response) except Exception as e: print("Exception when calling BackgroundRunsApi->get_run: %s\n" % e) ``` -------------------------------- ### Thread Model Usage Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/Thread.md Demonstrates how to create a Thread instance from a JSON string, convert it to a dictionary, and create a Thread from a dictionary. Ensure the JSON string is valid. ```python from ap_client.models.thread import Thread # TODO update the JSON string below json = "{}" # create an instance of Thread from a JSON string thread_instance = Thread.from_json(json) # print the JSON string representation of the object print(Thread.to_json()) # convert the object into a dict thread_dict = thread_instance.to_dict() # create an instance of Thread from a dict thread_from_dict = Thread.from_dict(thread_dict) ``` -------------------------------- ### WebSocket Response: Error Source: https://github.com/langchain-ai/agent-protocol/blob/main/streaming/README.md Example of a server-to-client error response to a command. Includes the command ID (if available), error type, and a descriptive message. ```json { "type": "error", "id": 1, "error": "invalid_argument", "message": "assistantId is required" } ``` -------------------------------- ### Instantiate ThreadCreate from JSON and Dict Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/ThreadCreate.md Demonstrates creating a ThreadCreate instance from a JSON string and a dictionary. Use `from_json` for JSON input and `from_dict` for dictionary input. The `to_json` and `to_dict` methods can be used for conversion. ```python from ap_client.models.thread_create import ThreadCreate # TODO update the JSON string below json = "{}" # create an instance of ThreadCreate from a JSON string thread_create_instance = ThreadCreate.from_json(json) # print the JSON string representation of the object print(ThreadCreate.to_json()) # convert the object into a dict thread_create_dict = thread_create_instance.to_dict() # create an instance of ThreadCreate from a dict thread_create_from_dict = ThreadCreate.from_dict(thread_create_dict) ``` -------------------------------- ### Content Block Delta: Multimodal Data Example Source: https://github.com/langchain-ai/agent-protocol/blob/main/streaming/README.md Streams encoded data chunks for multimodal content. Uses 'data-delta' for base64 encoded data. ```json { "event": "content-block-delta", "index": 1, "delta": { "type": "data-delta", "data": "UklGR...", "encoding": "base64" } } ``` -------------------------------- ### StorePutRequest Model Usage Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/StorePutRequest.md Demonstrates how to create a StorePutRequest instance from a JSON string and a dictionary, and how to convert it back to JSON or a dictionary. Ensure the JSON string is valid. ```python from ap_client.models.store_put_request import StorePutRequest # TODO update the JSON string below json = "{}" # create an instance of StorePutRequest from a JSON string store_put_request_instance = StorePutRequest.from_json(json) # print the JSON string representation of the object print(StorePutRequest.to_json()) # convert the object into a dict store_put_request_dict = store_put_request_instance.to_dict() # create an instance of StorePutRequest from a dict store_put_request_from_dict = StorePutRequest.from_dict(store_put_request_dict) ``` -------------------------------- ### Create AgentCapabilities Instance from JSON Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/AgentCapabilities.md Demonstrates how to create an AgentCapabilities object from a JSON string and convert it to a dictionary. Ensure the JSON string is valid and represents the AgentCapabilities structure. ```python from ap_client.models.agent_capabilities import AgentCapabilities # TODO update the JSON string below json = "{}" # create an instance of AgentCapabilities from a JSON string agent_capabilities_instance = AgentCapabilities.from_json(json) # print the JSON string representation of the object print(AgentCapabilities.to_json()) # convert the object into a dict agent_capabilities_dict = agent_capabilities_instance.to_dict() # create an instance of AgentCapabilities from a dict agent_capabilities_from_dict = AgentCapabilities.from_dict(agent_capabilities_dict) ``` -------------------------------- ### Get a Thread by ID using Python Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/ThreadsApi.md Shows how to retrieve a thread's details using its ID. This is useful for fetching the current state of a conversation. ```python import ap_client from ap_client.models.thread import Thread from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) # Enter a context with an instance of the API client with ap_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = ap_client.ThreadsApi(api_client) thread_id = 'thread_id_example' # str | The ID of the thread. try: # Get Thread api_response = api_instance.get_thread(thread_id) print("The response of ThreadsApi->get_thread:\n") pprint(api_response) except Exception as e: print("Exception when calling ThreadsApi->get_thread: %s\n" % e) ``` -------------------------------- ### List Namespaces using StoreApi Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/StoreApi.md This method lists available namespaces in the store. It requires a StoreListNamespacesRequest object. Ensure the host configuration is correctly set. ```python import ap_client from ap_client.models.store_list_namespaces_request import StoreListNamespacesRequest from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) ``` -------------------------------- ### Get Agent by ID using Python Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/AgentsApi.md Use this method to retrieve a specific agent by its unique identifier. Ensure the agent ID is correctly formatted. ```python import ap_client from ap_client.models.agent import Agent from ap_client.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to http://localhost # See configuration.py for a list of all supported configuration parameters. configuration = ap_client.Configuration( host = "http://localhost" ) # Enter a context with an instance of the API client with ap_client.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = ap_client.AgentsApi(api_client) agent_id = 'agent_id_example' # str | The ID of the agent. try: # Get Agent api_response = api_instance.get_agent(agent_id) print("The response of AgentsApi->get_agent:\n") pprint(api_response) except Exception as e: print("Exception when calling AgentsApi->get_agent: %s\n" % e) ``` -------------------------------- ### List Namespaces Source: https://github.com/langchain-ai/agent-protocol/blob/main/client-python/docs/StoreApi.md Retrieves a list of all available namespaces in the store. ```APIDOC ## GET /namespaces ### Description Lists all namespaces in the store. ### Method GET ### Endpoint /namespaces ### Parameters #### Query Parameters - **store_list_namespaces_request** (StoreListNamespacesRequest) - Required - The request object for listing namespaces. ### Request Example ```json { "example": "{}\n" } ``` ### Response #### Success Response (200) - **List[List[str]]** - A list of namespaces. #### Response Example ```json { "example": "[\n [\n "namespace1",\n "namespace2"\n ]\n]" } ``` ``` -------------------------------- ### Content Block Delta: Text Example Source: https://github.com/langchain-ai/agent-protocol/blob/main/streaming/README.md Streams text content for a message's content block. Appends to the active block's 'text' field. ```json { "event": "content-block-delta", "index": 0, "delta": { "type": "text-delta", "text": "Hello " } } ```