Skip to content

Protocol

The runtime-neutral boundary every tactic shares, whatever runtime it uses. Import these from lllm, except the base class Tactic: it is lllm.protocol.Tactic, while lllm.Tactic is the native tactic, which subclasses it. Guides: Typed I/O, Other runtimes, Pydantic AI.

Tactic

Tactic

Tactic(*, name: str | None = None, description: str | None = None, package_ref: str | None = None, service_ref: str | None = None, examples: list[dict[str, Any]] | None = None, metadata: Mapping[str, Any] | None = None)

Bases: Generic[InputT, OutputT]

Typed, service-ready unit that does one thing well.

Subclasses normally implement _run for synchronous tactics, _arun for async-only tactics, or both for runtimes with specialized behavior. run and arun are the public validated boundary methods.

info

info() -> TacticInfo

Return the tactic's stable public contract.

run

run(input_value: InputT, *, context: CallContext | None = None, return_trace: bool = False, **kwargs: Any) -> OutputT | CallResult

Run the tactic synchronously through the validated boundary.

arun async

arun(input_value: InputT, *, context: CallContext | None = None, return_trace: bool = False, **kwargs: Any) -> OutputT | CallResult

Run the tactic asynchronously through the validated boundary.

CallContext

Bases: BaseModel

Metadata supplied to one tactic invocation.

This is request metadata, not runtime configuration. Runtime-specific settings stay with the runtime adapter or user-owned runtime object.

call_id property

call_id: str

Compatibility alias for older boundary traces.

CallResult

Bases: BaseModel

Optional local result envelope with trace data.

TacticEvent

Bases: BaseModel

A small event emitted by a streaming tactic.

TacticInfo

Bases: BaseModel

Static description of a tactic boundary.

Other runtimes

as_tactic

as_tactic(fn: Callable[..., Any], *, name: str | None = None, description: str | None = None, input_type: Any = None, output_type: Any = None, package_ref: str | None = None, service_ref: str | None = None, examples: list[dict[str, Any]] | None = None, metadata: Mapping[str, Any] | None = None) -> CallableTactic

Return a tactic wrapper for a Python callable.

A tactic passed without overrides is returned as it is.

NativeTacticAdapter

NativeTacticAdapter(native: Any, *, name: str | None = None, description: str | None = None, input_type: Any = None, output_type: Any = None, package_ref: str | None = None, service_ref: str | None = None, examples: list[dict[str, Any]] | None = None, metadata: dict[str, Any] | None = None, run_kwargs: Mapping[str, Any] | None = None, include_context_metadata: bool = True)

Bases: Tactic[Any, Any]

Wrap a native-style object behind the protocol Tactic boundary.

PydanticAITactic

PydanticAITactic(agent: Any, config: Any = None, *, name: str | None = None, input_type: Any = None, output_type: Any = None, description: str | None = None, package_ref: str | None = None, service_ref: str | None = None, examples: list[dict[str, Any]] | None = None, input_mode: InputMode | None = None, result_mode: ResultMode | None = None, stream_mode: StreamMode | None = None, include_context_metadata: bool | None = None, run_kwargs: dict[str, Any] | None = None, input_mapper: Callable[[Any], Any] | None = None, output_mapper: Callable[[Any], Any] | None = None, metadata: Mapping[str, Any] | None = None)

Bases: Tactic[Any, Any]

Expose a Pydantic AI agent as an LLLM tactic.

tactic_as_tool

tactic_as_tool(tactic: Tactic[Any, Any], *, name: str | None = None, description: str | None = None, parameter_mode: Literal['task', 'kwargs'] = 'task') -> Callable[..., Any]

Expose any LLLM tactic as a plain callable for runtime-owned tool APIs.

Refs

TacticRef dataclass

TacticRef(value: str)

A stable lllm://org/package/tactics/name tactic reference.

Resolver

Resolver(*, tactics: TacticResolver | None = None, channels: 'ChannelResolver | None' = None, config: 'LocalConfigResolver | None' = None)

One entry point for tactic, channel, and snapshot refs plus settings.

channels property writable

channels: 'ChannelResolver'

The sssn.ChannelResolver behind channel and snapshot refs.

It is created on first use; assign one to replace it.

from_config classmethod

from_config(path: str | Path = '.') -> 'Resolver'

Load .lllm/config.toml from a project folder or a file path.

register

register(ref: str, tactic: Tactic[Any, Any]) -> None

Bind a tactic ref to an in-process tactic.

store

store(ref: str) -> 'LocalStore | RemoteStore'

Return the store behind a channel or snapshot ref.

resolve

resolve(ref: str) -> Any

Resolve a ref by its section: tactics, channels, or snapshots.

Errors

LLLMError

Bases: RuntimeError

Base error raised by LLLM.

TacticError

Bases: ProtocolError

Raised when a tactic boundary fails.

TacticUnsupportedError

Bases: TacticError

Raised when a tactic does not support a requested capability.

TacticLoadError

Bases: TacticError

Raised when a tactic entrypoint cannot be loaded.

TacticRefError

Bases: TacticError

Raised when a tactic reference cannot be parsed or resolved.

SchemaError

Bases: ProtocolError

Raised when a schema cannot validate or describe data.

ProtocolError

Bases: LLLMError

Raised when protocol data is invalid.

TacticServiceError

Bases: TacticError

Raised when a remote tactic service returns an error.