1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2026 Chris Olson
// Portions derived from ADK-Go (https://github.com/google/adk-go), Copyright 2026 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Mode resolution; `is_untransferable_mode` decides from the declared mode which agents cannot
//! be transferred to.
//!
//! An agent that declares no mode takes one from where it is placed: chat at a runner root,
//! single_turn at a workflow node. The declaration (`LlmAgentConfig::mode`) is immutable, so the
//! resolved mode lives on the invocation as a binding instead: one agent instance serves many
//! concurrent invocations and may sit at two placements.
//!
//! Rules:
//! - Readers that only test for task mode stay on the declaration: no placement defaults to task.
//! - `is_untransferable_mode` and task-tool installation read the declaration: they decide the
//! shape of the agent tree, which a per-run placement cannot answer.
//! - The history half of the contents processor reads [`bound_mode`] directly, to tell a
//! single_turn placement from a single_turn declaration; every other reader resolves through
//! [`mode_for`].
//! - A binding is keyed by (agent name, `AgentState::key()`), so it never governs an agent it was
//! not resolved for, survives nested activations that bind other agents, and keeps two distinct
//! same-named agents in separate slots. Re-binding the same agent shadows the outer binding.
//! - An empty name binds like any other; binding `Mode::Unset` is a no-op. There is no way to clear
//! a binding.
use ;
use crate;
/// `declared` when set, else `by_placement`.
pub
/// `ctx` carrying the mode the named agent runs under for this invocation.
/// `Mode::Unset` returns `ctx` unchanged (a clone).
pub
/// The mode bound on an explicit (name, state) identity, if any.
pub
/// The mode on an explicit identity: the binding, else the declaration (`Unset` for
/// non-LLM agents).
pub
/// The mode bound to `agent` in `ctx`, if any.
pub
/// The mode `agent` runs under in `ctx`: the binding, else the declaration.
pub
/// Reads the declaration only; `ctx` is unused.
pub