Run the agent and handle HITL interrupts until the task completes. The loop is capped at `max_turns` when set, otherwise `_MAX_HITL_ITERATIONS`, to prevent runaway retries (e.g. the agent repeatedly attempting rejected commands). Args: agent: The agent (Pregel or RemoteAgen
(
agent: Any, # noqa: ANN401
message: str,
config: RunnableConfig,
console: Console,
file_op_tracker: FileOpTracker,
*,
quiet: bool = False,
stream: bool = True,
message_kwargs: dict[str, Any] | None = None,
thread_url_lookup: ThreadUrlLookupState | None = None,
max_turns: int | None = None,
rubric: str | None = None,
show_rubric_iterations: bool = False,
)
| 774 | |
| 775 | |
| 776 | async def _run_agent_loop( |
| 777 | agent: Any, # noqa: ANN401 |
| 778 | message: str, |
| 779 | config: RunnableConfig, |
| 780 | console: Console, |
| 781 | file_op_tracker: FileOpTracker, |
| 782 | *, |
| 783 | quiet: bool = False, |
| 784 | stream: bool = True, |
| 785 | message_kwargs: dict[str, Any] | None = None, |
| 786 | thread_url_lookup: ThreadUrlLookupState | None = None, |
| 787 | max_turns: int | None = None, |
| 788 | rubric: str | None = None, |
| 789 | show_rubric_iterations: bool = False, |
| 790 | ) -> None: |
| 791 | """Run the agent and handle HITL interrupts until the task completes. |
| 792 | |
| 793 | The loop is capped at `max_turns` when set, |
| 794 | otherwise `_MAX_HITL_ITERATIONS`, to prevent runaway retries |
| 795 | (e.g. the agent repeatedly attempting rejected commands). |
| 796 | |
| 797 | Args: |
| 798 | agent: The agent (Pregel or RemoteAgent). |
| 799 | message: The user's task message. |
| 800 | config: LangGraph runnable config. |
| 801 | console: Rich console for formatted output. |
| 802 | file_op_tracker: Tracker for file-operation diffs. |
| 803 | quiet: Suppress diagnostic formatting on stdout. |
| 804 | stream: When `True`, text is written to stdout as it arrives. |
| 805 | |
| 806 | When `False`, the full response is buffered and flushed at |
| 807 | the end. |
| 808 | message_kwargs: Extra fields merged into the initial HumanMessage |
| 809 | dict (e.g., `additional_kwargs` for persisted skill metadata). |
| 810 | thread_url_lookup: Optional non-blocking lookup state for rendering |
| 811 | a fast-follow LangSmith thread link. |
| 812 | max_turns: Optional cap on total agentic turns (initial response plus |
| 813 | HITL resumes). |
| 814 | |
| 815 | When `None`, falls back to `_MAX_HITL_ITERATIONS`. |
| 816 | rubric: Acceptance criteria supplied to `RubricMiddleware` via the |
| 817 | graph's `rubric` state field. |
| 818 | |
| 819 | `None` leaves it unset (no grading). |
| 820 | show_rubric_iterations: Whether rubric lifecycle messages should include |
| 821 | iteration numbers. |
| 822 | |
| 823 | Raises: |
| 824 | HITLIterationLimitError: If the effective turn limit is exceeded. |
| 825 | """ |
| 826 | spinner = None if quiet else _ConsoleSpinner(console) |
| 827 | state = StreamState( |
| 828 | quiet=quiet, |
| 829 | stream=stream, |
| 830 | spinner=spinner, |
| 831 | show_rubric_iterations=show_rubric_iterations, |
| 832 | ) |
| 833 | user_msg: dict[str, Any] = {"role": "user", "content": message} |
searching dependent graphs…