Use DeepAgents model resolver in builder graph
All checks were successful
build / build (push) Successful in 14s

This commit is contained in:
robert
2026-06-06 20:34:29 -03:00
parent c3259f2022
commit d9cbd7dd52

View File

@@ -3,12 +3,12 @@ from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from types import SimpleNamespace
from typing import Any from typing import Any
from deepagents import create_deep_agent from a2a_pack.deepagents import create_a2a_deep_agent
from deepagents.backends import CompositeBackend, StateBackend, StoreBackend from deepagents.backends import CompositeBackend, StateBackend, StoreBackend
from deepagents.backends.utils import create_file_data from deepagents.backends.utils import create_file_data
from langchain_openai import ChatOpenAI
from langgraph.store.memory import InMemoryStore from langgraph.store.memory import InMemoryStore
from .config import Settings, load_settings from .config import Settings, load_settings
@@ -50,8 +50,8 @@ control plane.
The default starter is the current a2a-pack DeepAgents scaffold. It declares The default starter is the current a2a-pack DeepAgents scaffold. It declares
``LLMProvisioning.PLATFORM``, reads the caller's saved LLM credential from ``LLMProvisioning.PLATFORM``, reads the caller's saved LLM credential from
``ctx.llm``, builds a ``ChatOpenAI`` model from those credentials, and wires a small ``ctx.llm``, resolves the model through ``create_a2a_deep_agent``, and wires a small
tool-calling DeepAgent with ``create_deep_agent`` plus ``wrap_model_call`` tool-calling DeepAgent with the A2A DeepAgents model middleware
middleware. Do not recreate this from memory: call ``init_agent_template`` first middleware. Do not recreate this from memory: call ``init_agent_template`` first
and modify the generated files. and modify the generated files.
@@ -60,8 +60,8 @@ Default hosted generated/user agents to ``LLMProvisioning.PLATFORM`` and
credential for the callee. The generated agent must still read ``ctx.llm`` and must never credential for the callee. The generated agent must still read ``ctx.llm`` and must never
read ``A2A_LITELLM_KEY``, ``OPENAI_API_KEY``, LiteLLM master keys, or provider read ``A2A_LITELLM_KEY``, ``OPENAI_API_KEY``, LiteLLM master keys, or provider
keys directly. ``LLMProvisioning.CALLER_PROVIDED`` is still acceptable for keys directly. ``LLMProvisioning.CALLER_PROVIDED`` is still acceptable for
explicit BYOK wording. Always make missing ``ctx.llm.api_key`` a clear setup/config result before constructing explicit BYOK wording. Always make missing ``ctx.llm.api_key`` a clear setup/config result before constructing
``ChatOpenAI``. a DeepAgents model.
``Pricing`` accepts only ``price_per_call_usd``, ``caller_pays_llm``, and ``Pricing`` accepts only ``price_per_call_usd``, ``caller_pays_llm``, and
``notes``. Never set ``runtime.pricing.compute`` or ``notes``. Never set ``runtime.pricing.compute`` or
``runtime.pricing.total_usd`` in generated source; those are derived later by ``runtime.pricing.total_usd`` in generated source; those are derived later by
@@ -325,21 +325,15 @@ def build_agent_builder(ctx: BuilderContext) -> Any:
grant_token=ctx.grant_token, grant_token=ctx.grant_token,
) )
) )
model_kwargs: dict[str, Any] = { llm_creds = SimpleNamespace(
"model": ctx.llm_model or settings.litellm_model, model=ctx.llm_model or settings.litellm_model,
"base_url": ctx.llm_base_url or (settings.litellm_url + "/v1"), base_url=ctx.llm_base_url or (settings.litellm_url + "/v1"),
"api_key": ctx.llm_api_key or settings.litellm_key, api_key=ctx.llm_api_key or settings.litellm_key,
"stream_usage": True, temperature_mode=ctx.llm_temperature_mode or "default",
} temperature=ctx.llm_temperature,
if ctx.llm_temperature_mode != "omit": extra_body=dict(ctx.llm_extra_body or {}),
model_kwargs["temperature"] = (
ctx.llm_temperature if ctx.llm_temperature is not None else 0.0
) )
if ctx.llm_extra_body:
model_kwargs["extra_body"] = dict(ctx.llm_extra_body)
model = ChatOpenAI(**model_kwargs)
kwargs: dict[str, Any] = { kwargs: dict[str, Any] = {
"model": model,
"tools": tools, "tools": tools,
"system_prompt": SYSTEM_PROMPT, "system_prompt": SYSTEM_PROMPT,
} }
@@ -347,7 +341,12 @@ def build_agent_builder(ctx: BuilderContext) -> Any:
if backend is not None: if backend is not None:
kwargs["backend"] = backend kwargs["backend"] = backend
kwargs["skills"] = [BUILDER_SKILL_SOURCE] kwargs["skills"] = [BUILDER_SKILL_SOURCE]
return create_deep_agent(**kwargs) return create_a2a_deep_agent(
ctx,
creds=llm_creds,
default_temperature=0.0,
**kwargs,
)
def _build_project_backend(ctx: BuilderContext, *, settings: Settings) -> Any | None: def _build_project_backend(ctx: BuilderContext, *, settings: Settings) -> Any | None: