Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions libs/code/deepagents_code/_server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ class ServerConfig:
"""Extra kwargs forwarded to the chat model constructor (temperature,
max_tokens, etc.)."""

profile_overrides: dict[str, Any] | None = None
"""Model profile metadata overrides resolved by the client."""

assistant_id: str = DEFAULT_ASSISTANT_ID
"""Identifier of the agent graph to invoke on the server."""

Expand Down Expand Up @@ -339,6 +342,11 @@ def to_env(self) -> dict[str, str | None]:
"MODEL_PARAMS": (
json.dumps(self.model_params) if self.model_params is not None else None
),
"PROFILE_OVERRIDES": (
json.dumps(self.profile_overrides)
if self.profile_overrides is not None
else None
),
"ASSISTANT_ID": self.assistant_id,
"SYSTEM_PROMPT": self.system_prompt,
"AUTO_APPROVE": str(self.auto_approve).lower(),
Expand Down Expand Up @@ -396,6 +404,7 @@ def from_env(cls) -> ServerConfig:
return cls(
model=_read_env_str("MODEL"),
model_params=_read_env_json("MODEL_PARAMS"),
profile_overrides=_read_env_json("PROFILE_OVERRIDES"),
assistant_id=_read_env_str("ASSISTANT_ID") or DEFAULT_ASSISTANT_ID,
system_prompt=_read_env_str("SYSTEM_PROMPT"),
auto_approve=_read_env_bool("AUTO_APPROVE"),
Expand Down Expand Up @@ -440,6 +449,7 @@ def from_cli_args(
project_context: ProjectContext | None,
model_name: str | None,
model_params: dict[str, Any] | None,
profile_overrides: dict[str, Any] | None = None,
assistant_id: str,
auto_approve: bool,
interrupt_shell_only: bool = False,
Expand Down Expand Up @@ -470,6 +480,7 @@ def from_cli_args(
project_context: Explicit user/project path context.
model_name: Model spec string.
model_params: Extra model kwargs.
profile_overrides: Model profile metadata overrides.
assistant_id: Agent identifier.
auto_approve: Auto-approve all tools.
interrupt_shell_only: Validate shell commands via middleware instead
Expand Down Expand Up @@ -508,6 +519,7 @@ def from_cli_args(
return cls(
model=model_name,
model_params=model_params,
profile_overrides=profile_overrides,
assistant_id=assistant_id,
auto_approve=auto_approve,
interrupt_shell_only=interrupt_shell_only,
Expand Down
41 changes: 41 additions & 0 deletions libs/code/deepagents_code/_testing_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
DCA_TEST_WRITE_FILE_MARKER = "DCA_TEST_WRITE_FILE="
DCA_TEST_DELEGATE_WRITE_MARKER = "DCA_TEST_DELEGATE_WRITE="
DCA_SUBAGENT_WRITE_FILE_MARKER = "DCA_SUBAGENT_WRITE_FILE="
DCA_TEST_GOAL_CRITERIA_MARKER = "DCA_TEST_GOAL_CRITERIA="

# Distinct file contents per write path, so a test asserting on file content can
# prove which branch executed — in particular that subagent mode delegated through
Expand Down Expand Up @@ -303,3 +304,43 @@ def _marker_dispatch() -> tuple[
),
),
)


class GoalCriteriaIntegrationChatModel(DeterministicIntegrationChatModel):
"""Exercise nested criteria generation with a repository read."""

disable_streaming: bool = True

def _generate(
self,
messages: list[BaseMessage],
stop: list[str] | None = None, # noqa: ARG002
run_manager: CallbackManagerForLLMRun | None = None, # noqa: ARG002
**kwargs: Any, # noqa: ARG002
) -> ChatResult:
"""Read the marked file, then return a structured goal proposal.

Returns:
A repository tool call followed by a `GoalProposal` tool call.
"""
prompt = "\n".join(
text
for message in messages
if (text := self._stringify_message(message)).strip()
)
has_tool_result = any(message.type == "tool" for message in messages)
if DCA_TEST_GOAL_CRITERIA_MARKER in prompt and not has_tool_result:
path = _extract_marker_path(prompt, DCA_TEST_GOAL_CRITERIA_MARKER)
return _tool_call_result(
"read_file",
{"file_path": path, "limit": 20},
"call_goal_read",
)
return _tool_call_result(
"GoalProposal",
{
"objective": "verify server-side criteria generation",
"criteria": "- server repository context is available",
},
"call_goal_proposal",
)
33 changes: 33 additions & 0 deletions libs/code/deepagents_code/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,7 @@ def create_cli_agent(
cwd: str | Path | None = None,
project_context: ProjectContext | None = None,
async_subagents: list[AsyncSubAgent] | None = None,
goal_criteria_tools: Sequence[BaseTool | Callable[..., Any]] | None = None,
) -> tuple[Pregel[Any, Any, Any, Any], CompositeBackend]:
"""Create a CLI-configured agent with flexible options.

Expand Down Expand Up @@ -1542,6 +1543,8 @@ def create_cli_agent(
async_subagents: Remote LangGraph deployments to expose as async subagent tools.

Loaded from `[async_subagents]` in `config.toml` or passed directly.
goal_criteria_tools: External read-only context tools available to server-side
goal criteria generation. `None` disables goal criteria requests.

Returns:
2-tuple of `(agent_graph, backend)`
Expand Down Expand Up @@ -1935,6 +1938,36 @@ def _subagent_cli_middleware(*, has_explicit_model: bool) -> list[AgentMiddlewar
routes={},
)

if goal_criteria_tools is not None:
from deepagents_code.goal_rubric import (
GoalCriteriaMiddleware,
create_goal_criteria_agent,
)

if sandbox is not None:
if sandbox_type is not None:
criteria_backend = sandbox
criteria_root = get_default_working_dir(sandbox_type)
else:
criteria_backend = None
criteria_root = "/"
elif project_context is not None and project_context.project_root is not None:
criteria_backend = FilesystemBackend(
root_dir=project_context.project_root,
virtual_mode=True,
)
criteria_root = "/"
else:
criteria_backend = None
criteria_root = "/"
criteria_agent = create_goal_criteria_agent(
model=model,
repository_backend=criteria_backend,
repository_root=criteria_root,
context_tools=goal_criteria_tools,
)
agent_middleware.append(GoalCriteriaMiddleware(criteria_agent))

agent_middleware.append(_create_cli_compaction_middleware(model, composite_backend))

# Rubric-driven self-evaluation. The middleware is a no-op until a
Expand Down
Loading
Loading