langgraph_agent_toolkit.client.client module

exception langgraph_agent_toolkit.client.client.AgentClientError(*args, status_code=None, error_code=None, retry_after=None)[source][source]

Bases: Exception

Report a client failure with optional HTTP retry information.

Parameters:
  • args (Any)

  • status_code (int | None)

  • error_code (str | None)

  • retry_after (str | None)

Return type:

None

__init__(*args, status_code=None, error_code=None, retry_after=None)[source][source]
Parameters:
  • args (Any)

  • status_code (int | None)

  • error_code (str | None)

  • retry_after (str | None)

Return type:

None

class langgraph_agent_toolkit.client.client.AgentClient(base_url='http://0.0.0.0', agent=None, timeout=httpx.Timeout(60.0, connect=10.0, write=30.0, pool=10.0), get_info=True, verify=False, *, stream_timeout=httpx.Timeout(120.0, connect=10.0, write=30.0, pool=10.0), http_client=None, async_http_client=None, auth_secret=None)[source][source]

Bases: object

Client for the agent service.

Use a context manager to close owned HTTP connections. An async client must stay in one event loop until aclose() completes. The caller owns injected clients.

Initialize the client.

Parameters:
  • base_url (str) – Base URL of the agent service.

  • agent (str) – Default agent name.

  • timeout (float, optional) – Request timeout.

  • get_info (bool, optional) – Fetch agent information during initialization.

  • verify (bool, optional) – Verify agent information.

  • stream_timeout (float | Timeout | None) – Stream timeout. The read timeout limits idle time between chunks.

  • http_client (Client | None) – Optional shared sync client. The caller must close this client.

  • async_http_client (AsyncClient | None) – Optional shared async client. The caller must close this client.

  • auth_secret (str | None) – Optional bearer token. Defaults to AUTH_SECRET from the environment.

__init__(base_url='http://0.0.0.0', agent=None, timeout=httpx.Timeout(60.0, connect=10.0, write=30.0, pool=10.0), get_info=True, verify=False, *, stream_timeout=httpx.Timeout(120.0, connect=10.0, write=30.0, pool=10.0), http_client=None, async_http_client=None, auth_secret=None)[source][source]

Initialize the client.

Parameters:
  • base_url (str) – Base URL of the agent service.

  • agent (str) – Default agent name.

  • timeout (float, optional) – Request timeout.

  • get_info (bool, optional) – Fetch agent information during initialization.

  • verify (bool, optional) – Verify agent information.

  • stream_timeout (float | Timeout | None) – Stream timeout. The read timeout limits idle time between chunks.

  • http_client (Client | None) – Optional shared sync client. The caller must close this client.

  • async_http_client (AsyncClient | None) – Optional shared async client. The caller must close this client.

  • auth_secret (str | None) – Optional bearer token. Defaults to AUTH_SECRET from the environment.

Return type:

None

close()[source][source]

Close the owned sync client. Use aclose() to close async resources.

Return type:

None

async aclose()[source][source]

Close owned clients. Call this method in the loop that made the requests.

Return type:

None

retrieve_info()[source][source]
Return type:

None

update_agent(agent, verify=True)[source][source]
Parameters:
  • agent (str)

  • verify (bool)

Return type:

None

async ainvoke(input, model_name=None, model_provider=None, model_config_key=None, thread_id=None, user_id=None, agent_config=None, recursion_limit=None)[source][source]

Invoke the agent asynchronously and return its final message.

Parameters:
  • input (Dict[str, Any]) – The input to send to the agent

  • model_name (str, optional) – LLM model to use for the agent

  • model_provider (str | ModelProvider, optional) – LLM model provider to use for the agent

  • model_config_key (str, optional) – Key for predefined model configuration

  • thread_id (str, optional) – Thread ID for continuing a conversation

  • user_id (str, optional) – User ID for identifying the user

  • agent_config (dict[str, Any], optional) – Additional configuration to pass through to the agent

  • recursion_limit (int, optional) – Recursion limit for the agent

Returns:

The response from the agent

Return type:

ChatMessage

invoke(input, model_name=None, model_provider=None, model_config_key=None, thread_id=None, user_id=None, agent_config=None, recursion_limit=None)[source][source]

Invoke the agent synchronously and return its final message.

Parameters:
  • input (Dict[str, Any]) – The input to send to the agent

  • model_name (str, optional) – LLM model to use for the agent

  • model_provider (str | ModelProvider, optional) – LLM model provider to use for the agent

  • model_config_key (str, optional) – Key for predefined model configuration

  • thread_id (str, optional) – Thread ID for continuing a conversation

  • user_id (str, optional) – User ID for identifying the user

  • agent_config (dict[str, Any], optional) – Additional configuration to pass through to the agent

  • recursion_limit (int, optional) – Recursion limit for the agent

Returns:

The response from the agent

Return type:

ChatMessage

stream(input, model_name=None, model_provider=None, model_config_key=None, thread_id=None, user_id=None, agent_config=None, recursion_limit=None, stream_tokens=True)[source][source]

Stream agent responses synchronously.

Yield each intermediate ChatMessage. Yield content tokens when stream_tokens is True.

Parameters:
  • input (Dict[str, Any]) – The input to send to the agent

  • model_name (str, optional) – LLM model to use for the agent

  • model_provider (str, optional) – LLM model provider to use for the agent

  • model_config_key (str, optional) – Key for predefined model configuration

  • thread_id (str, optional) – Thread ID for continuing a conversation

  • user_id (str, optional) – User ID for identifying the user

  • agent_config (dict[str, Any], optional) – Additional configuration to pass through to the agent

  • recursion_limit (int, optional) – Recursion limit for the agent

  • stream_tokens (bool, optional) – Stream tokens as they are generated Default: True

Returns:

The response from the agent

Return type:

Generator[ChatMessage | str, None, None]

stream_jsonl(input, model_name=None, model_provider=None, model_config_key=None, thread_id=None, user_id=None, agent_config=None, recursion_limit=None, stream_tokens=True)[source][source]

Stream agent responses synchronously through the JSON Lines endpoint.

Yield the same ChatMessage | str values as stream. Use /stream/jsonl with media type application/jsonl instead of SSE.

Parameters:
  • input (Dict[str, Any])

  • model_name (str | None)

  • model_provider (str | ModelProvider | None)

  • model_config_key (str | None)

  • thread_id (str | None)

  • user_id (str | None)

  • agent_config (dict[str, Any] | None)

  • recursion_limit (int | None)

  • stream_tokens (bool)

Return type:

Generator[ChatMessage | str, None, None]

async astream(input, model_name=None, model_provider=None, model_config_key=None, thread_id=None, user_id=None, agent_config=None, recursion_limit=None, stream_tokens=True)[source][source]

Stream agent responses asynchronously.

Yield each intermediate ChatMessage. Yield content tokens when stream_tokens is True.

Parameters:
  • input (Dict[str, Any]) – The input to send to the agent

  • model_name (str, optional) – LLM model to use for the agent

  • model_provider (str, optional) – LLM model provider to use for the agent

  • model_config_key (str, optional) – Key for predefined model configuration

  • thread_id (str, optional) – Thread ID for continuing a conversation

  • user_id (str, optional) – User ID for identifying the user

  • agent_config (dict[str, Any], optional) – Additional configuration to pass through to the agent

  • recursion_limit (int, optional) – Recursion limit for the agent

  • stream_tokens (bool, optional) – Stream tokens as they are generated Default: True

Returns:

The response from the agent

Return type:

AsyncGenerator[ChatMessage | str, None]

async astream_jsonl(input, model_name=None, model_provider=None, model_config_key=None, thread_id=None, user_id=None, agent_config=None, recursion_limit=None, stream_tokens=True)[source][source]

Stream JSON Lines (NDJSON) responses asynchronously like stream_jsonl.

Parameters:
  • input (Dict[str, Any])

  • model_name (str | None)

  • model_provider (str | ModelProvider | None)

  • model_config_key (str | None)

  • thread_id (str | None)

  • user_id (str | None)

  • agent_config (dict[str, Any] | None)

  • recursion_limit (int | None)

  • stream_tokens (bool)

Return type:

AsyncGenerator[ChatMessage | str, None]

async acreate_feedback(run_id, key, score, kwargs={}, user_id=None, *, feedback_token=None)[source][source]

Create feedback for a run.

Parameters:
  • run_id (str) – Run ID for feedback.

  • key (str) – Feedback key.

  • score (float) – Feedback score.

  • kwargs (dict[str, Any], optional) – Additional feedback metadata.

  • user_id (str, optional) – User ID.

  • feedback_token (str | None) – Token from the run’s returned ChatMessage.

Return type:

FeedbackResponse

get_history(thread_id, user_id=None, *, offset=0, limit=100)[source][source]

Get short-term chat history.

Parameters:
  • thread_id (str) – Required ID for one short-term conversation.

  • user_id (str | None) – User who owns the conversation. This does not select long-term memory.

  • offset (int) – Number of messages to skip.

  • limit (int) – Maximum number of messages to return.

Return type:

ChatHistory

async aget_history(thread_id, user_id=None, *, offset=0, limit=100)[source][source]

Get short-term chat history asynchronously.

Parameters:
  • thread_id (str) – Required ID for one short-term conversation.

  • user_id (str | None) – User who owns the conversation. This does not select long-term memory.

  • offset (int) – Number of messages to skip.

  • limit (int) – Maximum number of messages to return.

Return type:

ChatHistory

clear_history(thread_id=None, user_id=None)[source][source]

Clear one conversation. Keep long-term memory.

Parameters:
  • thread_id (str | None) – Required ID for one short-term conversation.

  • user_id (str | None) – User who owns the conversation. This does not select long-term memory.

Return type:

ClearHistoryResponse

async aclear_history(thread_id=None, user_id=None)[source][source]

Clear one conversation asynchronously. Keep long-term memory.

Parameters:
  • thread_id (str | None) – Required ID for one short-term conversation.

  • user_id (str | None) – User who owns the conversation. This does not select long-term memory.

Return type:

ClearHistoryResponse

add_messages(messages, thread_id=None, user_id=None)[source][source]

Add messages to one short-term conversation.

Parameters:
  • messages (list[dict[str, str]] | list[MessageInput]) – Messages to add

  • thread_id (str | None) – Required ID for one short-term conversation.

  • user_id (str | None) – User who owns the conversation. This does not select long-term memory.

Return type:

AddMessagesResponse

async aadd_messages(messages, thread_id=None, user_id=None)[source][source]

Add messages to one short-term conversation asynchronously.

Parameters:
  • messages (list[dict[str, str]] | list[MessageInput]) – Messages to add

  • thread_id (str | None) – Required ID for one short-term conversation.

  • user_id (str | None) – User who owns the conversation. This does not select long-term memory.

Return type:

AddMessagesResponse

create_feedback(run_id, key, score, kwargs={}, user_id=None, *, feedback_token=None)[source][source]

Create a feedback record for a run.

Parameters:
  • run_id (str) – The ID of the run to provide feedback for

  • key (str) – The key for the feedback

  • score (float) – The score for the feedback

  • kwargs (dict[str, Any], optional) – Additional metadata for the feedback

  • user_id (str, optional) – User ID for identifying the user

  • feedback_token (str | None) – Token from the run’s returned ChatMessage.

Return type:

FeedbackResponse