fabricatio_tool.models.collector

Module for the ResultCollector class, which is used to collect, submit, revoke, and retrieve results in a container.

Classes

ApplicationError

Error raised during tool code execution, surfaced via ResultCollector.

ResultCollector

Used for collecting results as the task requests.

Module Contents

class fabricatio_tool.models.collector.ApplicationError

Error raised during tool code execution, surfaced via ResultCollector.

exc_type: str

e.g. ‘TypeError’

message: str

Exception message.

traceback: str

Formatted traceback (for LLM context).

source: str

The generated source code that failed (for LLM regeneration).

__str__() str

Return a human-readable representation of the error.

class fabricatio_tool.models.collector.ResultCollector

Used for collecting results as the task requests.

use .submit(key: str, val: Any) submit a result value val with the to the key slot. use .revoke(key: str) revoke a result from the container by its source key.

container: Dict[str, Any]

A dictionary to store results.

submit(key: str, val: Any) Self

Submit a result to the container with the specified key.

Parameters:
  • key (str) – The key to store the result under.

  • val (Any) – The result to store in the container.

Returns:

The current instance for method chaining.

Return type:

Self

revoke(key: str) Self

Remove a result from the container by its source key.

Parameters:

key (str) – The key of the result to remove.

Returns:

The current instance for method chaining.

Return type:

Self

Raises:

KeyError – If the key is not found in the container.

take[T](key: str, desired: Type[T] | None = None) T | None
take(key: List[str], desired: Type[T] | None = None) List[T | None]

Retrieve value(s) from the container by key(s) with optional type checking.

This method retrieves a single value or multiple values from the container based on the provided key(s). It supports optional type checking to ensure the retrieved value matches the expected type.

Parameters:
  • key (str | List[str]) – A single key as a string or a list of keys to retrieve values for.

  • desired (Optional[Type[T]]) – The expected type of the retrieved value(s). If provided, type checking will be performed and None will be returned for mismatched types.

Returns:

If key is a string, returns the value of type T or None.

If key is a list, returns a list of values of type T or None for each key.

Return type:

T | None | List[T | None]

error() ApplicationError | None

Return the ApplicationError if one was stored during execution.