tg_model.integrations¶
Integration boundaries for external computation and async-capable backends.
Bindings declared at definition time are compiled into graph nodes; sync evaluation
uses ExternalCompute, while
AsyncExternalCompute requires
evaluate_async.
See also
tg_model.execution.graph_compiler.compile_graph, tg_model.execution.evaluator.Evaluator
- class tg_model.integrations.AsyncExternalCompute(*args, **kwargs)[source]¶
Bases:
ProtocolCoroutine
computebackend (requiresevaluate_async()).- property name: str¶
- class tg_model.integrations.ExternalCompute(*args, **kwargs)[source]¶
Bases:
ProtocolSynchronous external backend (safe for
evaluate()).- property name: str¶
- class tg_model.integrations.ExternalComputeBinding(external, inputs, output_routes=None)[source]¶
Bases:
objectBind a callable to named input refs and optional output route refs.
- Parameters:
external (object)
inputs (dict[str, AttributeRef])
output_routes (dict[str, AttributeRef] | None)
- external: object¶
- inputs: dict[str, AttributeRef]¶
- output_routes: dict[str, AttributeRef] | None = None¶
- class tg_model.integrations.ExternalComputeResult(value, provenance=<factory>)[source]¶
Bases:
objectReturn value from
ExternalCompute.compute()/AsyncExternalCompute.compute().- Parameters:
value (Quantity | Mapping[str, Quantity])
provenance (Mapping[str, Any])
- value: Quantity | Mapping[str, Quantity]¶
- provenance: Mapping[str, Any]¶
- exception tg_model.integrations.ExternalComputeValidationError[source]¶
Bases:
ValueErrorRaised when
ValidatableExternalCompute.validate_binding()rejects a spec.
- class tg_model.integrations.ValidatableExternalCompute(*args, **kwargs)[source]¶
Bases:
ProtocolOptional static validation hook used by
tg_model.execution.validation.validate_graph().- validate_binding(*, input_specs, output_specs)[source]¶
Raise
ExternalComputeValidationErrororValueErrorwhen specs are inconsistent.- Parameters:
input_specs (Mapping[str, Any])
output_specs (Mapping[str, Any])
- Return type:
None
- tg_model.integrations.assert_sync_external(obj, *, context='')[source]¶
Raise
TypeErrorifobjis an async external.- Parameters:
obj (object) – External implementation about to run under sync evaluation.
context (str, optional) – Suffix appended to the error message.
- Raises:
TypeError – When
is_async_external()is true.- Return type:
None
- tg_model.integrations.is_async_external(obj)[source]¶
Return True when
computeis a coroutine function.Notes
Async externals must not run under
evaluate().- Parameters:
obj (object)
- Return type:
bool
- tg_model.integrations.link_external_routes(binding, routes)[source]¶
Mutate
binding.output_routesin place (authoring convenience).- Parameters:
binding (ExternalComputeBinding) – Target binding.
routes (dict[str, AttributeRef]) – Output name → attribute ref to realize.
- Return type:
None