> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-consol-1763754753-4714c41.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Manage assistants

In this guide we will show how to create, configure, and manage an [assistant](/langsmith/assistants).

First, as a brief refresher on the concept of context, consider the following simple `call_model` node and context schema.
Observe that this node tries to read and use the `model_name` as defined by the `context` object's `model_name` field.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    class ContextSchema(TypedDict):
        model_name: str

    builder = StateGraph(AgentState, context_schema=ContextSchema)

    def call_model(state, runtime: Runtime[ContextSchema]):
        messages = state["messages"]
        model = _get_model(runtime.context.get("model_name", "anthropic"))
        response = model.invoke(messages)
        # We return a list, because this will get added to the existing list
        return {"messages": [response]}
    ```
  </Tab>

  <Tab title="Javascript">
    ```js theme={null}
    import { Annotation } from "@langchain/langgraph";

    const ContextSchema = Annotation.Root({
        model_name: Annotation<string>,
        system_prompt:
    });

    const builder = new StateGraph(AgentState, ContextSchema)

    function callModel(state: State, runtime: Runtime[ContextSchema]) {
      const messages = state.messages;
      const model = _getModel(runtime.context.model_name ?? "anthropic");
      const response = model.invoke(messages);
      // We return a list, because this will get added to the existing list
      return { messages: [response] };
    }
    ```
  </Tab>
</Tabs>

For more information on configurations, [see here](/langsmith/configuration-cloud#configuration).

## Create an assistant

### LangGraph SDK

To create an assistant, use the [LangGraph SDK](/langsmith/sdk) `create` method. See the [Python](https://reference.langchain.com/python/langsmith/deployment/sdk/#langgraph_sdk.client.AssistantsClient.create) and [JS](https://reference.langchain.com/javascript/classes/_langchain_langgraph-sdk.client.AssistantsClient.html#create) SDK reference docs for more information.

This example uses the same context schema as above, and creates an assistant with `model_name` set to `openai`.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from langgraph_sdk import get_client

    client = get_client(url=<DEPLOYMENT_URL>)
    openai_assistant = await client.assistants.create(
        # "agent" is the name of a graph we deployed
        "agent", context={"model_name": "openai"}, name="Open AI Assistant"
    )

    print(openai_assistant)
    ```
  </Tab>

  <Tab title="Javascript">
    ```js theme={null}
    import { Client } from "@langchain/langgraph-sdk";

    const client = new Client({ apiUrl: <DEPLOYMENT_URL> });
    const openAIAssistant = await client.assistants.create({
        graphId: 'agent',
        name: "Open AI Assistant",
        context: { "model_name": "openai" },
    });

    console.log(openAIAssistant);
    ```
  </Tab>

  <Tab title="CURL">
    ```bash theme={null}
    curl --request POST \
        --url <DEPLOYMENT_URL>/assistants \
        --header 'Content-Type: application/json' \
        --data '{"graph_id":"agent", "context":{"model_name":"openai"}, "name": "Open AI Assistant"}'
    ```
  </Tab>
</Tabs>

Output:

```
{
"assistant_id": "62e209ca-9154-432a-b9e9-2d75c7a9219b",
"graph_id": "agent",
"name": "Open AI Assistant"
"context": {
"model_name": "openai"
}
"metadata": {}
"created_at": "2024-08-31T03:09:10.230718+00:00",
"updated_at": "2024-08-31T03:09:10.230718+00:00",
}
```

### LangSmith UI

You can also create assistants from the LangSmith UI.

Inside your deployment, select the "Assistants" tab. This will load a table of all of the assistants in your deployment, across all graphs.

To create a new assistant, select the "+ New assistant" button. This will open a form where you can specify the graph this assistant is for, as well as provide a name, description, and the desired configuration for the assistant based on the configuration schema for that graph.

To confirm, click "Create assistant". This will take you to [Studio](/langsmith/studio) where you can test the assistant. If you go back to the "Assistants" tab in the deployment, you will see the newly created assistant in the table.

## Use an assistant

### LangGraph SDK

We have now created an assistant called "Open AI Assistant" that has `model_name` defined as `openai`. We can now use this assistant with this configuration:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    thread = await client.threads.create()
    input = {"messages": [{"role": "user", "content": "who made you?"}]}
    async for event in client.runs.stream(
        thread["thread_id"],
        # this is where we specify the assistant id to use
        openai_assistant["assistant_id"],
        input=input,
        stream_mode="updates",
    ):
        print(f"Receiving event of type: {event.event}")
        print(event.data)
        print("\n\n")
    ```
  </Tab>

  <Tab title="Javascript">
    ```js theme={null}
    const thread = await client.threads.create();
    const input = { "messages": [{ "role": "user", "content": "who made you?" }] };

    const streamResponse = client.runs.stream(
      thread["thread_id"],
      // this is where we specify the assistant id to use
      openAIAssistant["assistant_id"],
      {
        input,
        streamMode: "updates"
      }
    );

    for await (const event of streamResponse) {
      console.log(`Receiving event of type: ${event.event}`);
      console.log(event.data);
      console.log("\n\n");
    }
    ```
  </Tab>

  <Tab title="CURL">
    ```bash theme={null}
    thread_id=$(curl --request POST \
        --url <DEPLOYMENT_URL>/threads \
        --header 'Content-Type: application/json' \
        --data '{}' | jq -r '.thread_id') && \
    curl --request POST \
        --url "<DEPLOYMENT_URL>/threads/${thread_id}/runs/stream" \
        --header 'Content-Type: application/json' \
        --data '{
            "assistant_id": <OPENAI_ASSISTANT_ID>,
            "input": {
                "messages": [
                    {
                        "role": "user",
                        "content": "who made you?"
                    }
                ]
            },
            "stream_mode": [
                "updates"
            ]
        }' | \
        sed 's/\r$//' | \
        awk '
        /^event:/ {
            if (data_content != "") {
                print data_content "\n"
            }
            sub(/^event: /, "Receiving event of type: ", $0)
            printf "%s...\n", $0
            data_content = ""
        }
        /^data:/ {
            sub(/^data: /, "", $0)
            data_content = $0
        }
        END {
            if (data_content != "") {
                print data_content "\n\n"
            }
        }
    '
    ```
  </Tab>
</Tabs>

Output:

```
Receiving event of type: metadata
{'run_id': '1ef6746e-5893-67b1-978a-0f1cd4060e16'}



Receiving event of type: updates
{'agent': {'messages': [{'content': 'I was created by OpenAI, a research organization focused on developing and advancing artificial intelligence technology.', 'additional_kwargs': {}, 'response_metadata': {'finish_reason': 'stop', 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_157b3831f5'}, 'type': 'ai', 'name': None, 'id': 'run-e1a6b25c-8416-41f2-9981-f9cfe043f414', 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None}]}}
```

### LangSmith UI

Inside your deployment, select the "Assistants" tab. For the assistant you would like to use, click the **Studio** button. This will open Studio with the selected assistant. When you submit an input (either in Graph or Chat mode), the selected assistant and its configuration will be used.

## Create a new version for your assistant

### LangGraph SDK

To edit the assistant, use the `update` method. This will create a new version of the assistant with the provided edits. See the [Python](https://reference.langchain.com/python/langsmith/deployment/sdk/#langgraph_sdk.client.AssistantsClient.update) and [JS](https://reference.langchain.com/javascript/classes/_langchain_langgraph-sdk.client.AssistantsClient.html#update) SDK reference docs for more information.

<Note>
  **Note**
  You must pass in the ENTIRE context (and metadata if you are using it). The update endpoint creates new versions completely from scratch and does not rely on previous versions.
</Note>

For example, to update your assistant's system prompt:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    openai_assistant_v2 = await client.assistants.update(
        openai_assistant["assistant_id"],
        context={
              "model_name": "openai",
              "system_prompt": "You are an unhelpful assistant!",
        },
    )
    ```
  </Tab>

  <Tab title="Javascript">
    ```js theme={null}
    const openaiAssistantV2 = await client.assistants.update(
        openai_assistant["assistant_id"],
        {
            context: {
                model_name: 'openai',
                system_prompt: 'You are an unhelpful assistant!',
            },
        },
    );
    ```
  </Tab>

  <Tab title="CURL">
    ```bash theme={null}
    curl --request PATCH \
    --url <DEPLOYMENT_URL>/assistants/<ASSISTANT_ID> \
    --header 'Content-Type: application/json' \
    --data '{
    "context": {"model_name": "openai", "system_prompt": "You are an unhelpful assistant!"}
    }'
    ```
  </Tab>
</Tabs>

This will create a new version of the assistant with the updated parameters and set this as the active version of your assistant. If you now run your graph and pass in this assistant id, it will use this latest version.

### LangSmith UI

You can also edit assistants from the LangSmith UI.

Inside your deployment, select the "Assistants" tab. This will load a table of all of the assistants in your deployment, across all graphs.

To edit an existing assistant, select the "Edit" button for the specified assistant. This will open a form where you can edit the assistant's name, description, and configuration.

Additionally, if using Studio, you can edit the assistants and create new versions via the "Manage Assistants" button.

## Use a previous assistant version

### LangGraph SDK

You can also change the active version of your assistant. To do so, use the `setLatest` method.

In the example above, to rollback to the first version of the assistant:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    await client.assistants.set_latest(openai_assistant['assistant_id'], 1)
    ```
  </Tab>

  <Tab title="Javascript">
    ```js theme={null}
    await client.assistants.setLatest(openaiAssistant['assistant_id'], 1);
    ```
  </Tab>

  <Tab title="CURL">
    ```bash theme={null}
    curl --request POST \
    --url <DEPLOYMENT_URL>/assistants/<ASSISTANT_ID>/latest \
    --header 'Content-Type: application/json' \
    --data '{
    "version": 1
    }'
    ```
  </Tab>
</Tabs>

If you now run your graph and pass in this assistant id, it will use the first version of the assistant.

### LangSmith UI

If using Studio, to set the active version of your assistant, click the "Manage Assistants" button and locate the assistant you would like to use. Select the assistant and the version, and then click the "Active" toggle. This will update the assistant to make the selected version active.

<Warning>
  **Deleting Assistants**
  Deleting as assistant will delete ALL of its versions. There is currently no way to delete a single version, but by pointing your assistant to the correct version you can skip any versions that you don't wish to use.
</Warning>

***

<Callout icon="pen-to-square" iconType="regular">
  [Edit the source of this page on GitHub.](https://github.com/langchain-ai/docs/edit/main/src/langsmith/configuration-cloud.mdx)
</Callout>

<Tip icon="terminal" iconType="regular">
  [Connect these docs programmatically](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
</Tip>
