invokeHarness method

Future<InvokeHarnessResponse> invokeHarness({
  1. required String harnessArn,
  2. required List<HarnessMessage> messages,
  3. required String runtimeSessionId,
  4. String? actorId,
  5. List<String>? allowedTools,
  6. String? baggage,
  7. int? maxIterations,
  8. int? maxTokens,
  9. HarnessModelConfiguration? model,
  10. String? qualifier,
  11. String? runtimeUserId,
  12. List<HarnessSkill>? skills,
  13. List<HarnessSystemContentBlock>? systemPrompt,
  14. int? timeoutSeconds,
  15. List<HarnessTool>? tools,
  16. String? traceId,
  17. String? traceParent,
  18. String? traceState,
})

Operation to invoke a Harness.

May throw AccessDeniedException. May throw InternalServerException. May throw ResourceNotFoundException. May throw RuntimeClientError. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

Parameter harnessArn : The ARN of the harness to invoke.

Parameter messages : The messages to send to the agent.

Parameter runtimeSessionId : The session ID for the invocation. Use the same session ID across requests to continue a conversation.

Parameter actorId : The actor ID for memory operations. Overrides the actor ID configured on the harness.

Parameter allowedTools : The tools that the agent is allowed to use for this invocation. If specified, overrides the harness default.

Parameter baggage : W3C Baggage header for user-defined context propagation. Format: key1=value1,key2=value2

Parameter maxIterations : The maximum number of iterations the agent loop can execute. If specified, overrides the harness default.

Parameter maxTokens : The maximum number of tokens the agent can generate per iteration. If specified, overrides the harness default.

Parameter model : The model configuration to use for this invocation. If specified, overrides the harness default.

Parameter qualifier : The endpoint name to invoke. If omitted, the DEFAULT endpoint is used.

Parameter runtimeUserId : An identifier for the end user making the request. This value is passed through to the runtime container.

Parameter skills : The skills available to the agent for this invocation. If specified, overrides the harness default.

Parameter systemPrompt : The system prompt to use for this invocation. If specified, overrides the harness default.

Parameter timeoutSeconds : The maximum duration in seconds for the agent loop execution. If specified, overrides the harness default.

Parameter tools : The tools available to the agent for this invocation. If specified, overrides the harness default.

Parameter traceId : Trace ID for maintaining observability through the operation.

Parameter traceParent : W3C trace context parent header containing version, trace ID, parent span ID, and trace flags.

Parameter traceState : W3C trace context state header for vendor-specific trace information.

Implementation

Future<InvokeHarnessResponse> invokeHarness({
  required String harnessArn,
  required List<HarnessMessage> messages,
  required String runtimeSessionId,
  String? actorId,
  List<String>? allowedTools,
  String? baggage,
  int? maxIterations,
  int? maxTokens,
  HarnessModelConfiguration? model,
  String? qualifier,
  String? runtimeUserId,
  List<HarnessSkill>? skills,
  List<HarnessSystemContentBlock>? systemPrompt,
  int? timeoutSeconds,
  List<HarnessTool>? tools,
  String? traceId,
  String? traceParent,
  String? traceState,
}) async {
  final headers = <String, String>{
    'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id':
        runtimeSessionId.toString(),
    if (baggage != null) 'baggage': baggage.toString(),
    if (runtimeUserId != null)
      'X-Amzn-Bedrock-AgentCore-Runtime-User-Id': runtimeUserId.toString(),
    if (traceId != null) 'X-Amzn-Trace-Id': traceId.toString(),
    if (traceParent != null) 'traceparent': traceParent.toString(),
    if (traceState != null) 'tracestate': traceState.toString(),
  };
  final $query = <String, List<String>>{
    'harnessArn': [harnessArn],
    if (qualifier != null) 'qualifier': [qualifier],
  };
  final $payload = <String, dynamic>{
    'messages': messages,
    if (actorId != null) 'actorId': actorId,
    if (allowedTools != null) 'allowedTools': allowedTools,
    if (maxIterations != null) 'maxIterations': maxIterations,
    if (maxTokens != null) 'maxTokens': maxTokens,
    if (model != null) 'model': model,
    if (skills != null) 'skills': skills,
    if (systemPrompt != null) 'systemPrompt': systemPrompt,
    if (timeoutSeconds != null) 'timeoutSeconds': timeoutSeconds,
    if (tools != null) 'tools': tools,
  };
  final response = await _protocol.sendRaw(
    payload: $payload,
    method: 'POST',
    requestUri: '/harnesses/invoke',
    queryParams: $query,
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  final $json = await _s.jsonFromResponse(response);
  return InvokeHarnessResponse(
    stream: InvokeHarnessStreamOutput.fromJson($json),
  );
}