Amazon BedrockΒΆ

Amazon Bedrock models can be called through the Bedrock Runtime Converse and Converse Stream APIs using the actions below.

Install the optional extra (pulls boto3):

pip install "burr[bedrock]"

IAM permissions must allow bedrock:InvokeModel / streaming equivalents for your chosen models; see AWS documentation for your account and model IDs.

class burr.integrations.bedrock.BedrockAction(
model_id: str,
input_mapper: StateToPromptMapper,
reads: list[str],
writes: list[str],
name: str = 'bedrock_invoke',
region: str | None = None,
guardrail_id: str | None = None,
guardrail_version: str | None = None,
inference_config: dict[str, Any] | None = None,
max_retries: int = 3,
client: Any | None = None,
)ΒΆ

Bases: _BedrockBase, SingleStepAction

Action that invokes Amazon Bedrock models using the Converse API.

Parameters:
  • model_id – Bedrock model identifier (e.g. Anthropic Claude on Bedrock).

  • input_mapper – Callable mapping State to Bedrock messages / optional system keys.

  • reads – State keys this action reads.

  • writes – State keys to update (typically include response).

  • name – Action name for the graph.

  • region – AWS region for the Bedrock runtime client (optional).

  • guardrail_id – If set, guardrail_version must also be set explicitly.

  • guardrail_version – Guardrail version string (use DRAFT only when intended).

  • inference_config – Passed as inferenceConfig; if omitted, defaults to a maxTokens limit. Pass an empty dict explicitly to send an empty config.

  • max_retries – Botocore retry configuration for the runtime client.

  • client – Optional pre-built bedrock-runtime client (for tests or injection).

Use run_and_update() to run the model and merge outputs into state.

run_and_update(
state: State,
**run_kwargs,
) tuple[dict, State]ΒΆ

Performs a run/update at the same time.

Parameters:
  • state – State to run the action on

  • run_kwargs – Additional arguments to the function passed at runtime.

Returns:

Result of the action and the new state

class burr.integrations.bedrock.BedrockStreamingAction(
model_id: str,
input_mapper: StateToPromptMapper,
reads: list[str],
writes: list[str],
name: str = 'bedrock_stream',
region: str | None = None,
guardrail_id: str | None = None,
guardrail_version: str | None = None,
inference_config: dict[str, Any] | None = None,
max_retries: int = 3,
client: Any | None = None,
)ΒΆ

Bases: _BedrockBase, StreamingAction

Streaming Bedrock action using the Converse Stream API.

Parameters match BedrockAction except the default name is bedrock_stream. Yields chunk dicts from stream_run() and merges the final response in update().

stream_run(
state: State,
**run_kwargs,
) Generator[dict, None, None]ΒΆ

Streaming action stream_run is different than standard action run. It: 1. streams in an intermediate result (the dict output) 2. yields the final result at the end

Note that the user, in this case, is responsible for joining the result.

For instance, you could have:

def stream_run(state: State) -> Generator[dict, None, dict]:
    buffer = [] # you might want to be more efficient than simple strcat
    for token in query(state['prompt']):
        yield {'response' : token}
        buffer.append(token)
    yield {'response' : "".join(buffer)}

This would utilize a simple string buffer (implemented by a list) to store the results and then join them at the end. We return the final result.

Parameters:
  • state – State to run the action on

  • run_kwargs – parameters passed to the run function – these are specified by inputs

Returns:

A generator that streams in a result and returns the final result

update(result: dict, state: State) StateΒΆ

Performs a state update given a result and the current state. Returns a new, modified State (recall state is immutable – simply changing the state in place will not work).

In the context of Burr, this is only applied in the two-step actions, where the run and update() functions are separate. The function-based APIs for Burr use the SingleStepAction class, which performs them both at once. This is not (yet) exposed as an interface for users to extend.

Parameters:
  • result – Result of a function executing on the state

  • state – State to update

Returns:

A new, modified state.