Skip to content

create_event

create_event(
    memory_id: MemoryId,
    actor_id: ActorId,
    event_timestamp: datetime,
    payload: PayloadTypeList,
    *,
    config_overrides: Optional[BedrockAgentCoreClientConfig] = None,
    session_id: Optional[SessionId] = None,
    branch: Optional[Branch] = None,
    client_token: Optional[str] = None,
    metadata: Optional[MetadataMap] = None,
    extraction_mode: Optional[ExtractionMode] = None,
    extraction_config: Optional[ExtractionConfig] = None,
) -> CreateEventOutput

Creates an event in an AgentCore Memory resource. Events represent interactions or activities that occur within a session and are associated with specific actors.

To use this operation, you must have the bedrock-agentcore:CreateEvent permission.

This operation is subject to request rate limiting.

Parameters:

  • memory_id (MemoryId) –

    The identifier of the AgentCore Memory resource in which to create the event.

  • actor_id (ActorId) –

    The identifier of the actor associated with this event. An actor represents an entity that participates in sessions and generates events.

  • session_id (Optional[SessionId], default: None ) –

    The identifier of the session in which this event occurs. A session represents a sequence of related events.

  • event_timestamp (datetime) –

    The timestamp when the event occurred. If not specified, the current time is used.

  • payload (PayloadTypeList) –

    The content payload of the event. This can include conversational data, JSON data, or binary content.

  • branch (Optional[Branch], default: None ) –

    The branch information for this event. Branches allow for organizing events into different conversation threads or paths.

  • client_token (Optional[str], default: None ) –

    A unique, case-sensitive identifier to ensure that the operation completes no more than one time. If this token matches a previous request, AgentCore ignores the request, but does not return an error.

  • metadata (Optional[MetadataMap], default: None ) –

    The key-value metadata to attach to the event.

  • extraction_mode (Optional[ExtractionMode], default: None ) –

    Controls long-term memory extraction for this event. When set to SKIP, the event is stored in short-term memory but is excluded from long-term memory extraction. If not specified, the event is processed for extraction as usual.

  • extraction_config (Optional[ExtractionConfig], default: None ) –

    The extraction configuration for long-term memory records. Use this parameter to specify namespace variable keys and their values for namespace substitution during extraction.

Raises:

  • AccessDeniedException –

    The exception that occurs when you do not have sufficient permissions to perform an action. Verify that your IAM policy includes the necessary permissions for the operation you are trying to perform.

  • InvalidInputException –

    The input fails to satisfy the constraints specified by AgentCore. Check your input values and try again.

  • ResourceNotFoundException –

    The exception that occurs when the specified resource does not exist. This can happen when using an invalid identifier or when trying to access a resource that has been deleted.

  • RetryableConflictException –

    The exception that occurs when there is a retryable conflict performing an operation. This is a temporary condition that may resolve itself with retries. We recommend implementing exponential backoff retry logic in your application.

  • ServiceException –

    The service encountered an internal error. Try your request again later.

  • ServiceQuotaExceededException –

    The exception that occurs when the request would cause a service quota to be exceeded. Review your service quotas and either reduce your request rate or request a quota increase.

  • ThrottledException –

    The request was denied due to request throttling. Reduce the frequency of requests and try again.

  • ValidationException –

    The exception that occurs when the input fails to satisfy the constraints specified by the service. Check the error message for details about which input parameter is invalid and correct your request.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_bedrock_agentcore/_services/bedrock_agent_core.py
def create_event(
    self,
    memory_id: "capo_bedrock_agentcore.types.memory_id.MemoryId",
    actor_id: "capo_bedrock_agentcore.types.actor_id.ActorId",
    event_timestamp: datetime.datetime,
    payload: "capo_bedrock_agentcore.types.payload_type_list.PayloadTypeList",
    *,
    config_overrides: Optional[BedrockAgentCoreClientConfig] = None,
    session_id: Optional[
        "capo_bedrock_agentcore.types.session_id.SessionId"
    ] = None,
    branch: Optional["capo_bedrock_agentcore.types.branch.Branch"] = None,
    client_token: Optional[str] = None,
    metadata: Optional[
        "capo_bedrock_agentcore.types.metadata_map.MetadataMap"
    ] = None,
    extraction_mode: Optional[
        "capo_bedrock_agentcore.types.extraction_mode.ExtractionMode"
    ] = None,
    extraction_config: Optional[
        "capo_bedrock_agentcore.types.extraction_config.ExtractionConfig"
    ] = None,
) -> "capo_bedrock_agentcore.types.create_event_output.CreateEventOutput":
    """<p>Creates an event in an AgentCore Memory resource. Events represent interactions or activities that occur within a session and are associated with specific actors.</p> <p>To use this operation, you must have the <code>bedrock-agentcore:CreateEvent</code> permission.</p> <p>This operation is subject to request rate limiting.</p>

    Args:
        memory_id: <p>The identifier of the AgentCore Memory resource in which to create the event.</p>
        actor_id: <p>The identifier of the actor associated with this event. An actor represents an entity that participates in sessions and generates events.</p>
        session_id: <p>The identifier of the session in which this event occurs. A session represents a sequence of related events.</p>
        event_timestamp: <p>The timestamp when the event occurred. If not specified, the current time is used.</p>
        payload: <p>The content payload of the event. This can include conversational data, JSON data, or binary content.</p>
        branch: <p>The branch information for this event. Branches allow for organizing events into different conversation threads or paths.</p>
        client_token: <p>A unique, case-sensitive identifier to ensure that the operation completes no more than one time. If this token matches a previous request, AgentCore ignores the request, but does not return an error.</p>
        metadata: <p>The key-value metadata to attach to the event.</p>
        extraction_mode: <p>Controls long-term memory extraction for this event. When set to <code>SKIP</code>, the event is stored in short-term memory but is excluded from long-term memory extraction. If not specified, the event is processed for extraction as usual.</p>
        extraction_config: <p>The extraction configuration for long-term memory records. Use this parameter to specify namespace variable keys and their values for namespace substitution during extraction.</p>

    Raises:
        capo_bedrock_agentcore.errors.access_denied_exception.AccessDeniedException: <p>The exception that occurs when you do not have sufficient permissions to perform an action. Verify that your IAM policy includes the necessary permissions for the operation you are trying to perform.</p>
        capo_bedrock_agentcore.errors.invalid_input_exception.InvalidInputException: <p>The input fails to satisfy the constraints specified by AgentCore. Check your input values and try again.</p>
        capo_bedrock_agentcore.errors.resource_not_found_exception.ResourceNotFoundException: <p>The exception that occurs when the specified resource does not exist. This can happen when using an invalid identifier or when trying to access a resource that has been deleted.</p>
        capo_bedrock_agentcore.errors.retryable_conflict_exception.RetryableConflictException: <p>The exception that occurs when there is a retryable conflict performing an operation. This is a temporary condition that may resolve itself with retries. We recommend implementing exponential backoff retry logic in your application.</p>
        capo_bedrock_agentcore.errors.service_exception.ServiceException: <p>The service encountered an internal error. Try your request again later.</p>
        capo_bedrock_agentcore.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The exception that occurs when the request would cause a service quota to be exceeded. Review your service quotas and either reduce your request rate or request a quota increase.</p>
        capo_bedrock_agentcore.errors.throttled_exception.ThrottledException: <p>The request was denied due to request throttling. Reduce the frequency of requests and try again.</p>
        capo_bedrock_agentcore.errors.validation_exception.ValidationException: <p>The exception that occurs when the input fails to satisfy the constraints specified by the service. Check the error message for details about which input parameter is invalid and correct your request.</p>
        capo_bedrock_agentcore.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_bedrock_agentcore.types.create_event_input.CreateEventInput]",
    ) -> OperationResponse[
        "capo_bedrock_agentcore.types.create_event_output.CreateEventOutput"
    ]:
        import capo_bedrock_agentcore._operations.amazon_bedrock_agent_core.create_event

        output, http_response = (
            capo_bedrock_agentcore._operations.amazon_bedrock_agent_core.create_event.create_event(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_bedrock_agentcore.types.create_event_input.CreateEventInput",
    ) -> dict[str, Any]:
        import capo_bedrock_agentcore.types.create_event_input

        return capo_bedrock_agentcore.types.create_event_input.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_bedrock_agentcore.types.create_event_output.CreateEventOutput",
    ) -> dict[str, Any]:
        import capo_bedrock_agentcore.types.create_event_output

        return capo_bedrock_agentcore.types.create_event_output.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateEvent", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_bedrock_agentcore.types.create_event_input.CreateEventInput = {
        "memory_id": memory_id,
        "actor_id": actor_id,
        "event_timestamp": event_timestamp,
        "payload": payload,
    }
    if session_id is not None:
        input_["session_id"] = session_id
    if branch is not None:
        input_["branch"] = branch
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if metadata is not None:
        input_["metadata"] = metadata
    if extraction_mode is not None:
        input_["extraction_mode"] = extraction_mode
    if extraction_config is not None:
        input_["extraction_config"] = extraction_config

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output