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. int? maxIterations,
  7. int? maxTokens,
  8. HarnessModelConfiguration? model,
  9. String? runtimeUserId,
  10. List<HarnessSkill>? skills,
  11. List<HarnessSystemContentBlock>? systemPrompt,
  12. int? timeoutSeconds,
  13. List<HarnessTool>? tools,
})

Operation to invoke a Harness.

May throw AccessDeniedException. May throw InternalServerException. May throw ResourceNotFoundException. May throw RuntimeClientError. 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 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 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.

Implementation

Future<InvokeHarnessResponse> invokeHarness({
  required String harnessArn,
  required List<HarnessMessage> messages,
  required String runtimeSessionId,
  String? actorId,
  List<String>? allowedTools,
  int? maxIterations,
  int? maxTokens,
  HarnessModelConfiguration? model,
  String? runtimeUserId,
  List<HarnessSkill>? skills,
  List<HarnessSystemContentBlock>? systemPrompt,
  int? timeoutSeconds,
  List<HarnessTool>? tools,
}) async {
  final headers = <String, String>{
    'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id':
        runtimeSessionId.toString(),
    if (runtimeUserId != null)
      'X-Amzn-Bedrock-AgentCore-Runtime-User-Id': runtimeUserId.toString(),
  };
  final $query = <String, List<String>>{
    'harnessArn': [harnessArn],
  };
  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),
  );
}