open-swe/agent/middleware/__init__.py

22 lines
843 B
Python
Raw Normal View History

from .check_message_queue import check_message_queue_before_model
from .ensure_no_empty_msg import ensure_no_empty_msg
feat: add reviewer graph + eval target wiring (#1241) * feat: add reviewer graph + eval target wiring - New `reviewer` graph (`agent/reviewer.py`) registered in langgraph.json alongside the main `agent` graph. Reuses the same sandbox lifecycle, GH proxy auth, and middleware primitives from `agent.server`, but with a narrower tool set, a reviewer-specific system prompt, no commit/push, and the `task` (subagent) tool stripped via `_ToolExclusionMiddleware` so review stays in one context. - New `github_comment` tool: agents call it once per issue with `(file, line, body, severity)` and the eval scores those calls against golden comments. - `ensure_no_empty_msg` middleware (the no_op nudge) is intentionally *not* on the reviewer's stack — that middleware exists to enforce the main agent's "always finalize via Slack/Linear/PR" contract, which the reviewer doesn't have. The main agent's behavior is unchanged. - `evals/reviewer/target.py`: send PR info as a user message, extract every `github_comment` tool call (multiple expected per review) into the run output. - `evals/reviewer/judge.py`: per-example evaluator now returns a list of metrics under `{"results": [...]}` so LangSmith averages each numeric key (f1/precision/recall/tp/fp/fn) across the experiment in the UI. Dropped the broken `aggregate_pr` summary evaluator that reached for an attribute that doesn't exist on `RunTree`. - `evals/reviewer/run_eval.py`: `--limit` now slices the dataset via `client.list_examples(limit=N)` since `aevaluate` doesn't accept `max_examples`. - Makefile: `dev` and `run` targets now use `uv run` so they work without an activated venv. * resolve comments --------- Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
2026-05-06 10:15:58 -07:00
from .exclude_tools import ExcludeToolsMiddleware
from .model_fallback import ModelFallbackMiddleware
from .notify_step_limit import notify_step_limit_reached
feat: add optional Slack Assistants API typing status indicator (#1269) * feat: add optional Slack Assistants API typing status indicator Mirrors OpenClaw's pragmatic approach: instead of rebuilding around assistant_thread_started events, just opt into assistants.threads.setStatus to show 'is thinking…' while the agent is working, and clear it when post_slack_thread_reply lands. Gated behind SLACK_ASSISTANTS_API_ENABLED so it can be toggled without touching code. * fix(slack): drop redundant clear, add status heartbeat across model calls - Slack auto-clears the typing indicator on bot post; remove the explicit assistants.threads.setStatus("") call from post_slack_thread_reply. - The indicator expires after ~2 minutes; add a before_model middleware that refreshes it on every model tick so it stays visible across long agent runs. Reuses the existing slack_thread.{channel_id,thread_ts} configurable already plumbed for notify_step_limit. - chat:write is sufficient on the bot token (assistant:write is on the way out per Slack docs); no scope or app-config change required. * feat(slack): contextual status text + rotating loading_messages - set_slack_assistant_status now accepts an optional loading_messages list (capped at 10 per Slack's API), surfaced via the assistants.threads.setStatus payload so Slack rotates through them client-side. - The heartbeat middleware derives a contextual status from the last assistant message's tool calls (e.g. "searching the codebase…" after grep, "running commands…" after execute), falling back to the default "is thinking…" when no tool calls or unknown tool name. - Adds a curated DEFAULT_LOADING_MESSAGES list passed alongside the contextual status on each refresh. * fix slack assistant status lifecycle --------- Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com> Co-authored-by: Johannes du Plessis <johannes@langchain.dev>
2026-05-08 10:21:55 -07:00
from .refresh_slack_status import SlackAssistantStatusMiddleware
from .sandbox_circuit_breaker import SandboxCircuitBreakerMiddleware
from .sanitize_tool_inputs import SanitizeToolInputsMiddleware
from .tool_error_handler import ToolErrorMiddleware
__all__ = [
feat: add reviewer graph + eval target wiring (#1241) * feat: add reviewer graph + eval target wiring - New `reviewer` graph (`agent/reviewer.py`) registered in langgraph.json alongside the main `agent` graph. Reuses the same sandbox lifecycle, GH proxy auth, and middleware primitives from `agent.server`, but with a narrower tool set, a reviewer-specific system prompt, no commit/push, and the `task` (subagent) tool stripped via `_ToolExclusionMiddleware` so review stays in one context. - New `github_comment` tool: agents call it once per issue with `(file, line, body, severity)` and the eval scores those calls against golden comments. - `ensure_no_empty_msg` middleware (the no_op nudge) is intentionally *not* on the reviewer's stack — that middleware exists to enforce the main agent's "always finalize via Slack/Linear/PR" contract, which the reviewer doesn't have. The main agent's behavior is unchanged. - `evals/reviewer/target.py`: send PR info as a user message, extract every `github_comment` tool call (multiple expected per review) into the run output. - `evals/reviewer/judge.py`: per-example evaluator now returns a list of metrics under `{"results": [...]}` so LangSmith averages each numeric key (f1/precision/recall/tp/fp/fn) across the experiment in the UI. Dropped the broken `aggregate_pr` summary evaluator that reached for an attribute that doesn't exist on `RunTree`. - `evals/reviewer/run_eval.py`: `--limit` now slices the dataset via `client.list_examples(limit=N)` since `aevaluate` doesn't accept `max_examples`. - Makefile: `dev` and `run` targets now use `uv run` so they work without an activated venv. * resolve comments --------- Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
2026-05-06 10:15:58 -07:00
"ExcludeToolsMiddleware",
"ModelFallbackMiddleware",
"SanitizeToolInputsMiddleware",
"ToolErrorMiddleware",
"SandboxCircuitBreakerMiddleware",
feat: add optional Slack Assistants API typing status indicator (#1269) * feat: add optional Slack Assistants API typing status indicator Mirrors OpenClaw's pragmatic approach: instead of rebuilding around assistant_thread_started events, just opt into assistants.threads.setStatus to show 'is thinking…' while the agent is working, and clear it when post_slack_thread_reply lands. Gated behind SLACK_ASSISTANTS_API_ENABLED so it can be toggled without touching code. * fix(slack): drop redundant clear, add status heartbeat across model calls - Slack auto-clears the typing indicator on bot post; remove the explicit assistants.threads.setStatus("") call from post_slack_thread_reply. - The indicator expires after ~2 minutes; add a before_model middleware that refreshes it on every model tick so it stays visible across long agent runs. Reuses the existing slack_thread.{channel_id,thread_ts} configurable already plumbed for notify_step_limit. - chat:write is sufficient on the bot token (assistant:write is on the way out per Slack docs); no scope or app-config change required. * feat(slack): contextual status text + rotating loading_messages - set_slack_assistant_status now accepts an optional loading_messages list (capped at 10 per Slack's API), surfaced via the assistants.threads.setStatus payload so Slack rotates through them client-side. - The heartbeat middleware derives a contextual status from the last assistant message's tool calls (e.g. "searching the codebase…" after grep, "running commands…" after execute), falling back to the default "is thinking…" when no tool calls or unknown tool name. - Adds a curated DEFAULT_LOADING_MESSAGES list passed alongside the contextual status on each refresh. * fix slack assistant status lifecycle --------- Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com> Co-authored-by: Johannes du Plessis <johannes@langchain.dev>
2026-05-08 10:21:55 -07:00
"SlackAssistantStatusMiddleware",
"check_message_queue_before_model",
"ensure_no_empty_msg",
"notify_step_limit_reached",
]