oas2mcp.agent.base

Thin LangChain v1 agent factory helpers for oas2mcp.

Purpose:

Provide shared helpers for constructing LangChain v1 agents and the default OpenAI-backed chat model used by oas2mcp workflows.

Design:
  • Keep the wrapper intentionally thin.

  • Centralize common defaults such as runtime context schema and state schema.

  • Centralize default model construction, reasoning configuration, and environment loading.

  • Leave workflow-specific prompts, middleware, and structured outputs to submodules like summarizer and enhancer.

Examples

model = build_default_chat_model()
agent = build_base_agent(
    model=model,
    response_format=MyOutputModel,
)

Attributes

Functions

build_base_agent(*, response_format[, tools, ...])

Build a stateful LangChain v1 agent for oas2mcp.

build_default_chat_model(→ langchain_openai.ChatOpenAI)

Build the default OpenAI chat model.

load_project_env(→ None)

Load likely project-local environment files.

require_openai_api_key(→ str)

Return the OpenAI API key from the environment.

Module Contents

oas2mcp.agent.base.build_base_agent(*, response_format: Any, tools: list[Any] | None = None, middleware: list[Any] | None = None, system_prompt: str | None = None, model: Any | None = None, model_name: str = DEFAULT_MODEL_NAME, reasoning_effort: str = DEFAULT_REASONING_EFFORT, model_kwargs: dict[str, Any] | None = None)[source][source]

Build a stateful LangChain v1 agent for oas2mcp.

Parameters:
  • response_format – Structured output schema or strategy.

  • tools – Optional tools.

  • middleware – Optional middleware stack.

  • system_prompt – Optional base system prompt.

  • model – Optional model instance or model identifier.

  • model_name – Default model name when model is omitted.

  • reasoning_effort – Default reasoning effort when model is omitted.

  • model_kwargs – Extra kwargs used only when building the default model.

Returns:

The constructed LangChain agent runnable.

Raises:

RuntimeError – If the default model is used and no API key is available.

oas2mcp.agent.base.build_default_chat_model(*, model_name: str = DEFAULT_MODEL_NAME, reasoning_effort: str = DEFAULT_REASONING_EFFORT, api_key: str | None = None, **kwargs: Any) langchain_openai.ChatOpenAI[source][source]

Build the default OpenAI chat model.

Parameters:
  • model_name – The OpenAI model name.

  • reasoning_effort – The reasoning effort to request.

  • api_key – Optional OpenAI API key.

  • **kwargs – Extra keyword arguments forwarded to ChatOpenAI.

Returns:

Configured chat model.

Return type:

ChatOpenAI

Raises:

RuntimeError – If no API key is available.

oas2mcp.agent.base.load_project_env() None[source][source]

Load likely project-local environment files.

Parameters:

None.

Returns:

None.

Raises:

None.

oas2mcp.agent.base.require_openai_api_key() str[source][source]

Return the OpenAI API key from the environment.

Parameters:

None.

Returns:

The resolved API key.

Return type:

str

Raises:

RuntimeError – If the key is not available.

oas2mcp.agent.base.DEFAULT_MODEL_NAME = 'gpt-5.1'[source][source]
oas2mcp.agent.base.DEFAULT_REASONING_EFFORT = 'high'[source][source]