Skip to content

Bedrock Agent

create_item(item_id, name, description=None)

Create a new item.

Parameters:

Name Type Description Default
item_id str

Unique identifier for the item.

required
name str

Name of the item.

required
description str | None

Optional description of the item.

None

Returns:

Type Description
dict

The created item details.

Source code in templates/agent/handler.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@tracer.capture_method
@app.tool(name="createItem", description="Creates a new item with name and optional description")
def create_item(item_id: str, name: str, description: str | None = None) -> dict:
    """Create a new item.

    Args:
        item_id: Unique identifier for the item.
        name: Name of the item.
        description: Optional description of the item.

    Returns:
        The created item details.
    """
    logger.info(f"Creating item {item_id}")
    item = Item(id=item_id, name=name, description=description)
    repository.put_item(item.model_dump())
    return item.model_dump(by_alias=True, exclude_none=True)

get_item(item_id)

Retrieve an item by its ID.

Parameters:

Name Type Description Default
item_id str

The unique identifier of the item.

required

Returns:

Type Description
dict

The item details or an error message.

Source code in templates/agent/handler.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@tracer.capture_method
@app.tool(name="getItem", description="Gets item details by ID")
def get_item(item_id: str) -> dict:
    """Retrieve an item by its ID.

    Args:
        item_id: The unique identifier of the item.

    Returns:
        The item details or an error message.
    """
    logger.info(f"Retrieving item {item_id}")
    item = repository.get_item(item_id)
    if not item:
        return {"error": f"Item {item_id} not found"}
    return item

main(event, context)

Lambda entry point for the Bedrock Agent handler.

Parameters:

Name Type Description Default
event dict | BedrockAgentEvent

The Bedrock Agent event.

required
context LambdaContext

The Lambda execution context.

required

Returns:

Type Description
dict

The Bedrock Agent function response.

Source code in templates/agent/handler.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@logger.inject_lambda_context
@tracer.capture_lambda_handler
@metrics.log_metrics
def main(event: dict | BedrockAgentEvent, context: LambdaContext) -> dict:
    """Lambda entry point for the Bedrock Agent handler.

    Args:
        event: The Bedrock Agent event.
        context: The Lambda execution context.

    Returns:
        The Bedrock Agent function response.
    """
    return app.resolve(event, context)