Skip to content

Commit

Permalink
Added bedrock client as a agent parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
brnaba-aws committed Sep 30, 2024
1 parent 8edcac9 commit 64e83cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion typescript/src/agents/amazonBedrockAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Logger } from "../utils/logger";
export interface AmazonBedrockAgentOptions extends AgentOptions {
agentId: string; // The ID of the Amazon Bedrock agent.
agentAliasId: string; // The alias ID of the Amazon Bedrock agent.
client?: BedrockAgentRuntimeClient; // Client for interacting with the Bedrock agent runtime.
}


Expand All @@ -31,7 +32,7 @@ export class AmazonBedrockAgent extends Agent {
super(options);
this.agentId = options.agentId;
this.agentAliasId = options.agentAliasId;
this.client = options.region
this.client = options.client ? options.client : options.region
? new BedrockAgentRuntimeClient({ region: options.region })
: new BedrockAgentRuntimeClient();
}
Expand Down
17 changes: 8 additions & 9 deletions typescript/src/agents/bedrockLLMAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface BedrockLLMAgentOptions extends AgentOptions {
customSystemPrompt?: {
template: string, variables?: TemplateVariables
};
client?: BedrockRuntimeClient;
}

/**
Expand Down Expand Up @@ -86,7 +87,7 @@ export class BedrockLLMAgent extends Agent {
constructor(options: BedrockLLMAgentOptions) {
super(options);

this.client = options.region
this.client = options.client ? options.client : options.region
? new BedrockRuntimeClient({ region: options.region })
: new BedrockRuntimeClient();

Expand Down Expand Up @@ -118,14 +119,14 @@ export class BedrockLLMAgent extends Agent {
- Ask for clarification if any part of the question or prompt is ambiguous.
- Maintain a consistent, respectful, and engaging tone tailored to the human's communication style.
- Seamlessly transition between topics as the human introduces new subjects.`

if (options.customSystemPrompt) {
this.setSystemPrompt(
options.customSystemPrompt.template,
options.customSystemPrompt.variables
);
}

}

/**
Expand Down Expand Up @@ -175,7 +176,7 @@ export class BedrockLLMAgent extends Agent {
const converseCmd = {
modelId: this.modelId,
messages: conversation, //Include the updated conversation history
system: [{ text: systemPrompt }],
system: [{ text: systemPrompt }],
inferenceConfig: {
maxTokens: this.inferenceConfig.maxTokens,
temperature: this.inferenceConfig.temperature,
Expand All @@ -197,7 +198,7 @@ export class BedrockLLMAgent extends Agent {

// Append the model's response to the ongoing conversation
conversation.push(bedrockResponse);

// process model response
if (bedrockResponse.content.some((content) => 'toolUse' in content)){
// forward everything to the tool use handler
Expand All @@ -210,7 +211,7 @@ export class BedrockLLMAgent extends Agent {
maxRecursions--;

converseCmd.messages = conversation;

}
return finalMessage;
}
Expand Down Expand Up @@ -254,7 +255,7 @@ export class BedrockLLMAgent extends Agent {
throw error;
}
}


setSystemPrompt(template?: string, variables?: TemplateVariables): void {
if (template) {
Expand Down Expand Up @@ -294,6 +295,4 @@ export class BedrockLLMAgent extends Agent {
return match; // If no replacement found, leave the placeholder as is
});
}


}

0 comments on commit 64e83cd

Please sign in to comment.