symfonic.agent.backend¶
backend ¶
The simple facade's adapter onto the W2 invocation kernel.
This package is what replaced symfonic.agent._bootstrap. The bootstrap was
a second way to set up an invocation, sanctioned in W1 only because the
legacy engine could not back a hermetic, quiet facade, and chartered to
disappear the moment a kernel existed. It has: the loop it carried now lives
once, in symfonic.kernel, and what remains here is adaptation — the wire
format, the provider handshake, and the facade's own value types.
Nothing in this package drives a round loop, decides how many provider calls an invocation may make, or assigns event indices. Those are kernel decisions, and keeping them there is the difference between an adapter and a second engine.
AgentPlanFactory
dataclass
¶
AgentPlanFactory(model_provider: Any, instructions: str | None, tools: NormalizedTools, max_model_rounds: int = MAX_TOOL_ITERATIONS, model: ModelConfig | None = None, role_models: Mapping[str, ModelConfig] = dict(), stages: tuple[Any, ...] = (), stage_handlers: Mapping[str, Any] = dict(), tool_preconditions: tuple[Any, ...] = (), authorized_effects: frozenset[str] = frozenset({'model_call'}), capability_names: tuple[str, ...] = ())
Turns the facade's four construction inputs into a compiled plan.
compile ¶
compile(output_type: type[BaseModel] | None, *, sink_factory: Callable[[ModelResolution], Any] | None = None) -> InvocationPlan
Validate eagerly, bind the ports, and compile exactly one plan.
sink_factory is the seam ServiceBindings.event_sink reserved.
It is called at most once, here, with the ModelResolution this plan
was compiled with, and whatever it returns is bound as the sink;
None — the simple facade's answer, which has no callback input —
leaves the binding unset, and InvocationRunner then constructs no
CallbackEventAdapter at all.
A factory rather than a sink because the two things a sink needs are produced on opposite sides of this call: the caller owns the run's identity (its id, its session, its tenant) and this method owns the model that identity has to name. Handing the resolution out rather than making the caller re-derive it keeps one answer to "which model ran?" — the caller's copy cannot drift from the plan's, because it is the plan's.
Binding it here rather than on the caller's side is also what makes the
sink's reference frozen at compile time along with every other port
(IPL-4). equality_key excludes bindings, so a bound sink changes
neither the config digest nor plan identity (IPL-7): two runs of the
same agent still compile the same plan shape with different sinks.
Source code in src/symfonic/agent/backend/plan.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
merge_capability_tools ¶
merge_capability_tools(adopter: Sequence[Any], contributed: Sequence[tuple[str, Any]]) -> NormalizedTools
Normalise the adopter's tools and the capabilities' into one set.
One set, because the tool path is read in four places — bind_tools, the
G4 manifest, ToolAdapter, and the tool_call grant — and a second
collection that only some of them consult is exactly how a tool becomes
bindable and not callable.
contributed is (capability, tool) pairs, which is why this exists
rather than a bare normalize_tools(list(a) + list(b)). Every refusal
below names the capability. A collision reported as "tools[4] resolves to
the name 'run_agent', which is already registered by an earlier tool" is
true and tells the adopter nothing about which capability to configure —
and unlike tools=[...], the adopter did not write the offending list
and cannot see it.
The adopter's tools go first and keep the plain index in their messages, so an error in a hand-written list reads exactly as it did before capabilities could contribute anything.
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
for a non-tool object, or for any name collision — capability against adopter, or capability against capability. |
Source code in src/symfonic/agent/backend/tools.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
normalize_tools ¶
Accept the three documented input forms; reject everything else.
Accepted (FAC-6): an object produced by @symfonic_tool(...), any
LangChain BaseTool, or a plain Python callable with annotated
parameters and a docstring — adapted through symfonic_tool() with its
documented defaults.
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
for a non-tool object (naming it and its index), or for two tools resolving to the same name. Last-one-wins would silently drop a tool the adopter believes is registered, so the collision is a hard error rather than a warning. |