createHarness method
- required String executionRoleArn,
- required String harnessName,
- List<
String> ? allowedTools, - AuthorizerConfiguration? authorizerConfiguration,
- String? clientToken,
- HarnessEnvironmentProviderRequest? environment,
- HarnessEnvironmentArtifact? environmentArtifact,
- Map<
String, String> ? environmentVariables, - int? maxIterations,
- int? maxTokens,
- HarnessMemoryConfiguration? memory,
- HarnessModelConfiguration? model,
- List<
HarnessSkill> ? skills, - List<
HarnessSystemContentBlock> ? systemPrompt, - Map<
String, String> ? tags, - int? timeoutSeconds,
- List<
HarnessTool> ? tools, - HarnessTruncationConfiguration? truncation,
Operation to create a Harness.
May throw AccessDeniedException.
May throw ConflictException.
May throw InternalServerException.
May throw ServiceQuotaExceededException.
May throw ThrottlingException.
May throw ValidationException.
Parameter executionRoleArn :
The ARN of the IAM role that the harness assumes when running. This role
must have permissions for the services the agent needs to access, such as
Amazon Bedrock for model invocation.
Parameter harnessName :
The name of the harness. Must start with a letter and contain only
alphanumeric characters and underscores.
Parameter allowedTools :
The tools that the agent is allowed to use. Supports glob patterns such as
- for all tools, @builtin for all built-in tools, or @serverName/toolName for specific MCP server tools.
Parameter clientToken :
A unique, case-sensitive identifier to ensure idempotency of the request.
Parameter environment :
The compute environment configuration for the harness, including network
and lifecycle settings.
Parameter environmentArtifact :
The environment artifact for the harness, such as a custom container image
containing additional dependencies.
Parameter environmentVariables :
Environment variables to set in the harness runtime environment.
Parameter maxIterations :
The maximum number of iterations the agent loop can execute per
invocation.
Parameter maxTokens :
The maximum total number of output tokens the agent can generate across
all model calls within a single invocation.
Parameter memory :
The AgentCore Memory configuration for persisting conversation context
across sessions.
Parameter model :
The model configuration for the harness. Supports Amazon Bedrock, OpenAI,
and Google Gemini model providers.
Parameter skills :
The skills available to the agent. Skills are bundles of files that the
agent can pull into its context on demand.
Parameter systemPrompt :
The system prompt that defines the agent's behavior and instructions.
Parameter tags :
Tags to apply to the harness resource.
Parameter timeoutSeconds :
The maximum duration in seconds for the agent loop execution per
invocation.
Parameter tools :
The tools available to the agent, such as remote MCP servers, AgentCore
Gateway, AgentCore Browser, Code Interpreter, or inline functions.
Parameter truncation :
The truncation configuration for managing conversation context when it
exceeds model limits.
Implementation
Future<CreateHarnessResponse> createHarness({
required String executionRoleArn,
required String harnessName,
List<String>? allowedTools,
AuthorizerConfiguration? authorizerConfiguration,
String? clientToken,
HarnessEnvironmentProviderRequest? environment,
HarnessEnvironmentArtifact? environmentArtifact,
Map<String, String>? environmentVariables,
int? maxIterations,
int? maxTokens,
HarnessMemoryConfiguration? memory,
HarnessModelConfiguration? model,
List<HarnessSkill>? skills,
List<HarnessSystemContentBlock>? systemPrompt,
Map<String, String>? tags,
int? timeoutSeconds,
List<HarnessTool>? tools,
HarnessTruncationConfiguration? truncation,
}) async {
final $payload = <String, dynamic>{
'executionRoleArn': executionRoleArn,
'harnessName': harnessName,
if (allowedTools != null) 'allowedTools': allowedTools,
if (authorizerConfiguration != null)
'authorizerConfiguration': authorizerConfiguration,
'clientToken': clientToken ?? _s.generateIdempotencyToken(),
if (environment != null) 'environment': environment,
if (environmentArtifact != null)
'environmentArtifact': environmentArtifact,
if (environmentVariables != null)
'environmentVariables': environmentVariables,
if (maxIterations != null) 'maxIterations': maxIterations,
if (maxTokens != null) 'maxTokens': maxTokens,
if (memory != null) 'memory': memory,
if (model != null) 'model': model,
if (skills != null) 'skills': skills,
if (systemPrompt != null) 'systemPrompt': systemPrompt,
if (tags != null) 'tags': tags,
if (timeoutSeconds != null) 'timeoutSeconds': timeoutSeconds,
if (tools != null) 'tools': tools,
if (truncation != null) 'truncation': truncation,
};
final response = await _protocol.send(
payload: $payload,
method: 'POST',
requestUri: '/harnesses',
exceptionFnMap: _exceptionFns,
);
return CreateHarnessResponse.fromJson(response);
}