Skip to content

Commit

Permalink
Apply PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nadheesh committed Jan 26, 2024
1 parent cf2a0a8 commit 29c61d4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 11 deletions.
4 changes: 1 addition & 3 deletions ballerina/agent.bal
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,4 @@ isolated function getObservationString(anydata|error observation) returns string
#
# + agent - Agent instance
# + return - Array of tools registered with the agent
public isolated function getTools(BaseAgent agent) returns AgentTool[] {
return agent.toolStore.tools.toArray();
}
public isolated function getTools(BaseAgent agent) returns AgentTool[] => agent.toolStore.tools.toArray();
2 changes: 1 addition & 1 deletion ballerina/error.bal
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public type HttpResponseParsingError distinct HttpServiceToolKitError;
public type ToolExecutionError distinct error;

# Error during unexpected output by the tool
public type ToolInvaludOutputError distinct ToolExecutionError;
public type ToolInvalidOutputError distinct ToolExecutionError;

# Errors occurred due to invalid tool name generated by the LLM.
public type ToolNotFoundError distinct LlmInvalidGenerationError;
Expand Down
3 changes: 1 addition & 2 deletions ballerina/function_call.bal
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ public isolated class FunctionCallAgent {

isolated function selectNextTool(ExecutionProgress progress) returns json|LlmError {
ChatMessage[] messages = createFunctionCallMessages(progress);
FunctionCall|string|LlmError functionaCall = self.model.functionaCall(messages,
return self.model.functionaCall(messages,
from AgentTool tool in self.toolStore.tools.toArray()
select {
name: tool.name,
description: tool.description,
parameters: tool.variables
});
return functionaCall;
}
}

Expand Down
6 changes: 2 additions & 4 deletions ballerina/react.bal
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public isolated class ReActAgent {
log:printDebug("Instruction Prompt Generated Successfully", instructionPrompt = self.instructionPrompt);
}

isolated function parseLlmResponse(json llmResponse) returns LlmToolResponse|LlmChatResponse|LlmInvalidGenerationError {
return parseReActLlmResponse(normalizeLlmResponse(llmResponse.toString()));
}
isolated function parseLlmResponse(json llmResponse) returns LlmToolResponse|LlmChatResponse|LlmInvalidGenerationError => parseReActLlmResponse(normalizeLlmResponse(llmResponse.toString()));

isolated function selectNextTool(ExecutionProgress progress) returns json|LlmError {
map<json>|string? context = progress.context;
Expand Down Expand Up @@ -157,7 +155,7 @@ isolated function extractToolInfo(ToolStore toolStore) returns ToolInfo {
description: tool.description,
inputSchema: tool.variables
};
toolIntroList.push(tool.name + ": " + toolDescription.toString());
toolIntroList.push(string `${tool.name}: ${toolDescription.toString()}`);
}
return {
toolList: string:'join(", ", ...toolNameList).trim(),
Expand Down
2 changes: 1 addition & 1 deletion ballerina/tool.bal
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ isolated class ToolStore {
return {value: observation};
}
if observation !is error {
return error ToolInvaludOutputError("Tool returns an invalid output. Expected anydata or error.", outputType = typeof observation, toolName = name, inputs = inputValues.length() == 0 ? {} : inputValues);
return error ToolInvalidOutputError("Tool returns an invalid output. Expected anydata or error.", outputType = typeof observation, toolName = name, inputs = inputValues.length() == 0 ? {} : inputValues);
}
if observation.message() == "{ballerina/lang.function}IncompatibleArguments" {
return error ToolInvalidInputError("Tool is provided with invalid inputs.", observation, toolName = name, inputs = inputValues.length() == 0 ? {} : inputValues, instruction = string `Tool "${name}" execution failed due to invalid inputs provided. Use the schema to provide inputs: ${self.tools.get(name).variables.toString()}`);
Expand Down

0 comments on commit 29c61d4

Please sign in to comment.