Skip to content

Commit

Permalink
Merge pull request #34 from nadheesh/main
Browse files Browse the repository at this point in the history
Improve query parameter serialization
  • Loading branch information
nadheesh authored Dec 6, 2023
2 parents 0476ce3 + 4322969 commit 3f38d4a
Show file tree
Hide file tree
Showing 16 changed files with 768 additions and 549 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ ballerina/Dependencies.toml
ballerina/Config.toml
ballerina/target
ballerina/sample*
ballerina/openapi*
ballerina/schem*
2 changes: 1 addition & 1 deletion ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
distribution = "2201.7.2"
org = "ballerinax"
name = "ai.agent"
version = "0.5.8"
version = "0.6.0"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = ["AI/Agent", "Cost/Freemium"]
Expand Down
35 changes: 19 additions & 16 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A tool refers to a single action used to retrieve, process, or manipulate data.
When using a Ballerina function as a tool, the function should adhere to the following template:

```ballerina
isolated function functionName(record parameters) returns anydata|error {
isolated function functionName(record{} parameters) returns anydata|error {
// function body
}
```
Expand Down Expand Up @@ -51,18 +51,19 @@ To use an API resource as a tool, an HTTP tool definition can be created as foll
agent:HttpTool httpResourceTool = {
name: "exampleTool", // used as an identifier
description: "defines the purpose of the API resource", // provides information about the behavior
path: "/path/resourceA/" // path to the resource
method: "get" // the HTTP request method (e.g., GET, POST, DELETE, PUT, etc.)
queryParameters: {
// a JSON schema defining the query parameters of the HTTP resource
},
pathParameters: {
// a JSON schema defining path parameters of the HTTP resource
path: "/path/resourceA/", // path to the resource
method: agent:GET, // the HTTP request method (e.g., GET, POST, DELETE, PUT, etc.)
parameters: {
// map of query and path parameter definitions
},
requestBody: {
// a JSON schema defining the request body of the HTTP resource
mediaType: "application/json", // the media type of the request body (optional)
schema: {
properties: {}
// a JSON schema defining the request body of the HTTP resource
}
}
}
};
```

### Tools from Interface Definition Languages (IDLs)
Expand Down Expand Up @@ -312,14 +313,16 @@ agent:HttpTool createWifiHttpTool = {
method: agent:POST,
description: "useful to create a guest wifi account.",
requestBody: {
'type: agent:OBJECT,
properties: {
email: {'type: agent:STRING},
username: {'type: agent:STRING},
password: {'type: agent:STRING}
schema: {
'type: agent:OBJECT,
properties: {
email: {'type: agent:STRING},
username: {'type: agent:STRING},
password: {'type: agent:STRING}
}
}
}
};
};
agent:HttpServiceToolKit wifiServiceToolKit = check new (wifiServiceUrl, [listWifiHttpTool, createWifiHttpTool], {
auth: {
Expand Down
35 changes: 19 additions & 16 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A tool refers to a single action used to retrieve, process, or manipulate data.
When using a Ballerina function as a tool, the function should adhere to the following template:

```ballerina
isolated function functionName(record parameters) returns anydata|error {
isolated function functionName(record{} parameters) returns anydata|error {
// function body
}
```
Expand Down Expand Up @@ -51,18 +51,19 @@ To use an API resource as a tool, an HTTP tool definition can be created as foll
agent:HttpTool httpResourceTool = {
name: "exampleTool", // used as an identifier
description: "defines the purpose of the API resource", // provides information about the behavior
path: "/path/resourceA/" // path to the resource
method: "get" // the HTTP request method (e.g., GET, POST, DELETE, PUT, etc.)
queryParameters: {
// a JSON schema defining the query parameters of the HTTP resource
},
pathParameters: {
// a JSON schema defining path parameters of the HTTP resource
path: "/path/resourceA/", // path to the resource
method: agent:GET, // the HTTP request method (e.g., GET, POST, DELETE, PUT, etc.)
parameters: {
// map of query and path parameter definitions
},
requestBody: {
// a JSON schema defining the request body of the HTTP resource
mediaType: "application/json", // the media type of the request body (optional)
schema: {
properties: {}
// a JSON schema defining the request body of the HTTP resource
}
}
}
};
```

### Tools from Interface Definition Languages (IDLs)
Expand Down Expand Up @@ -312,14 +313,16 @@ agent:HttpTool createWifiHttpTool = {
method: agent:POST,
description: "useful to create a guest wifi account.",
requestBody: {
'type: agent:OBJECT,
properties: {
email: {'type: agent:STRING},
username: {'type: agent:STRING},
password: {'type: agent:STRING}
schema: {
'type: agent:OBJECT,
properties: {
email: {'type: agent:STRING},
username: {'type: agent:STRING},
password: {'type: agent:STRING}
}
}
}
};
};
agent:HttpServiceToolKit wifiServiceToolKit = check new (wifiServiceUrl, [listWifiHttpTool, createWifiHttpTool], {
auth: {
Expand Down
2 changes: 1 addition & 1 deletion ballerina/agent.bal
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public isolated class Agent {
any|error observation = step?.observation;
if observation is error {
io:println("Observation (Error): " + observation.toString());
} else {
} else if observation !is () {
io:println("Observation: " + observation.toString());
}
}
Expand Down
16 changes: 2 additions & 14 deletions ballerina/constants.bal
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,12 @@ const DEFAULT_MAX_TOKEN_COUNT = 512;
const DEFAULT_TEMPERATURE = 0.7d;

// openapi
const OPENAPI_JSON_CONTENT_KEY = "application/json";
const OPENAPI_QUERY_PARAM_LOC_KEY = "query";
const OPENAPI_PATH_PARAM_LOC_KEY = "path";
const OPENAPI_COMPONENTS_KEY = "components";
const OPENAPI_PATTER_DATE = "yyyy-MM-dd";
const OPENAPI_PATTER_DATE_TIME = "yyyy-MM-dd'T'HH:mm:ssZ";
const OPENAPI_PATH_PARAM_SUPPORTED_STYLE = "simple";
const OPENAPI_QUERY_PARAM_SUPPORTED_STYLE = "form";
const OPENAPI_PATTERN_DATE = "yyyy-MM-dd";
const OPENAPI_PATTERN_DATE_TIME = "yyyy-MM-dd'T'HH:mm:ssZ";

//agent
const FINAL_ANSWER_KEY = "final answer";
const THOUGHT_KEY = "Thought:";
const BACKTICK = "`";
const ERROR_INSTRUCTION_KEY = "instruction";

//toolkit
const QUERY_PARAM_KEY = "queryParameters";
const PATH_PARAM_KEY = "pathParameters";
const REQUEST_BODY_KEY = "requestBody";
const PATH_KEY = "path";

21 changes: 19 additions & 2 deletions ballerina/error.bal
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ public type OpenApiParsingError distinct error;
# Stackoverflow errors due to lenthy OpenAPI specification or cyclic references in the specification.
public type ParsingStackOverflowError distinct OpenApiParsingError;

# Errors occurred due to unsupported path parameter serializations.
public type UnsupportedSerializationError distinct OpenApiParsingError;

# Errors due to unsupported OpenAPI specification version.
public type UnsupportedOpenApiVersion distinct OpenApiParsingError;

Expand All @@ -16,8 +19,8 @@ public type IncompleteSpecificationError distinct OpenApiParsingError;
# Errors due to unsupported media type.
public type UnsupportedMediaTypeError distinct OpenApiParsingError;

# Any error occurred during parsing HTTP response is classified under this error type.
public type HttpResponseParsingError distinct error;
# Error through due to invalid parameter definition that does not include either schema or content.
public type InvalidParameterDefinition distinct OpenApiParsingError;

# Any error occurred during LLM generation is classified under this error type.
public type LlmError distinct error;
Expand All @@ -31,3 +34,17 @@ public type LlmGenerationError distinct LlmError;
# Errors occurred due to termination of the Agent's execution.
public type TaskTerminationError distinct error;

# Errors occurred due while running HTTP service toolkit.
public type HttpServiceToolKitError distinct error;

# Any error occurred during parsing HTTP response is classified under this error type.
public type HttpResponseParsingError distinct HttpServiceToolKitError;

# Errors occurred due to invalid tool name generated by the LLM.
public type ToolNotFoundError distinct error;

# Errors occurred due to invalid input to the tool generated by the LLM.
public type ToolInvalidInputError distinct error;

# Errors occurred due to missing mandotary path or query parameters.
public type MissingHttpParameterError distinct ToolInvalidInputError;
Loading

0 comments on commit 3f38d4a

Please sign in to comment.