# Class LittleGhost::AssemblyBuilder

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/AssemblyBuilder.html

Builds an Assembly when its participants or routes are discovered at runtime.

Class definitions are the usual, easier-to-find way to declare behavior.
Builders expose the underlying dynamic form while preserving the same `ask`,
`stream_ask`, `call`, and `stream` interface:

    graph = LittleGhost::GraphBuilder.new(id: "support_flow")
    graph.node :triage, TriageAgent
    graph.node :respond, CustomerSupportAgent
    graph.start :triage
    graph.edge :triage, :respond
    graph.finish :respond
    graph.validate!

    run = graph.ask("Can I get a refund?")

A builder remains mutable. Each build or invocation copies its declarations
and referenced Assembly definitions. Later builder changes affect future
executions without changing an Assembly already built. Ruby closures and the
objects they reference remain live application code.

## Inheritance

`LittleGhost::AssemblyBuilder < Object`

## Attributes

<a id="attribute-i-runtime"></a>
### `runtime` (R)

Optional Runtime reused by standalone executions from this builder.

## Class methods

<a id="method-c-new"></a>
### `.new`

```ruby
.new(id: nil, description: nil, runtime: nil, base: nil)
```

Creates a mutable builder with optional identity, runtime, and base class.

## Instance methods

<a id="method-i-as_tool"></a>
### `#as_tool`

```ruby
#as_tool(**options)
```

Exposes the current declarations as a Tool.

<a id="method-i-ask"></a>
### `#ask`

```ruby
#ask(message, **options)
```

Executes the current declarations and returns their Run.

<a id="method-i-assembly_id"></a>
### `#assembly_id`

```ruby
#assembly_id(value = nil)
```

Reads or assigns the stable Assembly identifier.

<a id="method-i-assembly_kind"></a>
### `#assembly_kind`

```ruby
#assembly_kind()
```

Returns `:agent`, `:workflow`, `:swarm`, or
`:graph`.

<a id="method-i-build"></a>
### `#build`

```ruby
#build(runtime: self.runtime, run: nil)
```

Builds one execution instance from the current declarations.

<a id="method-i-call"></a>
### `#call`

```ruby
#call(input = nil, **options)
```

Executes the current declarations to completion.

<a id="method-i-definition"></a>
### `#definition`

```ruby
#definition()
```

Returns a complete definition for the builder's current declarations.

<a id="method-i-description"></a>
### `#description`

```ruby
#description(value = nil)
```

Reads or assigns the human-readable description.

<a id="method-i-start_execution"></a>
### `#start_execution`

```ruby
#start_execution(payload, &block)
```

Starts a supervised execution from the current declarations.

<a id="method-i-stream"></a>
### `#stream`

```ruby
#stream(input = nil, **options)
```

Streams the current declarations as StreamEvent objects.

<a id="method-i-stream_ask"></a>
### `#stream_ask`

```ruby
#stream_ask(message, **options)
```

Lazily streams an execution built from the current declarations.

<a id="method-i-validate-21"></a>
### `#validate!`

```ruby
#validate!()
```

Validates the builder's current declarations and returns this builder.
