The @or-sdk/agents
package provides a client for managing agents within the OneReach.ai ecosystem. With this client, you can perform operations such as creating, updating, retrieving, and deleting agents.
To install the package, run the following command:
$ npm install @or-sdk/agents
To use the Agents
client, you need to create an instance of the class with the appropriate configuration options. Here is an example:
import { Agents } from '@or-sdk/agents';
const agents = new Agents({
token: 'my-account-token-string',
serviceUrl: 'http://example.agents/endpoint',
accountId: 'your-account-id',
feature: 'master', // service feature name
});
Once you have an instance of the Agents
client, you can use its methods to interact with the agents system. The available methods are:
Create a new agent.
-
params
:CreateAgent
- An object containing the properties of the agent to create.
const newAgent = await agents.createAgent({
name: 'New Agent',
description: 'Description of the new agent',
// ...other properties
});
// Example response
{
id: 'new-agent-id',
name: 'New Agent',
description: 'Description of the new agent',
// ...other properties
}
Find agents with optional pagination and query.
-
params
:FindAgentsOptions
(optional) - Optional find parameters.
const agentsList = await agents.findAgents({
query: 'search query',
size: 10,
from: 0,
});
// Example response
{
items: [
{
id: 'agent-id',
name: 'Agent Name',
description: 'Agent Description',
// ...other properties
},
// ...more agents
],
total: 1
}
Get an agent by its ID.
-
agentId
:string
- The ID of the agent to retrieve.
const agent = await agents.getAgent('agent-id');
// Example response
{
id: 'agent-id',
name: 'Agent Name',
description: 'Agent Description',
// ...other properties
}
Update an agent by its ID.
-
agentId
:string
- The ID of the agent to update. -
params
:UpdateAgent
- The update agent parameters.
const updatedAgent = await agents.updateAgent('agent-id', {
name: 'Updated Agent Name',
description: 'Updated description',
// ...other update parameters
});
// Example response
{
id: 'agent-id',
name: 'Updated Agent Name',
description: 'Updated description',
// ...other properties
}
Delete an agent by its ID.
-
agentId
:string
- The ID of the agent to delete.
await agents.deleteAgent('agent-id');
// No direct response, the agent is deleted
Note: Deleting an agent is a permanent operation, and the removed data cannot be recovered. Be cautious when using this method and ensure you have backups of your data if necessary.
Set an action for an agent.
-
agentId
:string
- The ID of the agent for which to set the action. -
params
:AgentAction
- An object containing the properties of the action to set.
const actionParams = {
name: 'updateStatus',
description: 'Updates the status of an item',
typeDefs: `
input UpdateStatusInput {
id: ID!
status: String!
}
type UpdateStatusResult {
id: ID!
status: String!
}`,
examples: [
{
description: 'Update the status of item 123 to "processed"',
activities: [
{
kind: ActivityKind.Action,
input: 'updateStatus(input: { id: "123", status: "processed" })',
},
],
},
],
};
const setActionResponse = await agents.setAgentAction('agent-id', actionParams);
// Example response
{
name: 'updateStatus',
description: 'Updates the status of an item',
typeDefs: `
input UpdateStatusInput {
id: ID!
status: String!
}
type UpdateStatusResult {
id: ID!
status: String!
}`,
examples: [
{
description: 'Update the status of item 123 to "processed"',
activities: [
{
kind: ActivityKind.Action,
input: 'updateStatus(input: { id: "123", status: "processed" })',
},
],
},
],
}
Note: Setting an agent action allows you to define custom behaviors and operations that the agent can perform. Ensure that the typeDefs
and examples
are correctly defined to match the intended functionality of the action.
Delete a specific action of an agent.
-
agentId
:string
- The ID of the agent whose action is to be deleted. -
actionName
:string
- The name of the action to delete.
typescript
const actionName = 'updateStatus';
await agents.deleteAgentAction('agent-id', actionName);
// No direct response, the action is deleted
Retrieve a list of agent executions for a given agent.
-
agentId
:string
- The ID of the agent. -
params
:{ next?: string; maxKeys?: string; }
(optional) - Optional parameters for pagination (next, maxKeys).
const executions = await agents.getAgentExecutions('agent-id');
Retrieve the execution details of a specific agent.
-
agentId
:string
- The ID of the agent. -
executionId
:string
- The ID of the execution. -
options
:{}
(optional) - Additional options for the API call.
const execution = await agents.getAgentExecution('agent-id', 'execution-id');
Delete an agent execution.
-
agentId
:string
- The ID of the agent. -
executionId
:string
- The ID of the execution. -
options
:{}
(optional) - Additional options for the API call.
await agents.deleteAgentExecution('agent-id', 'execution-id');
// No direct response, the execution is deleted
This documentation update provides a basic overview of the @or-sdk/agents
package, including installation, usage, and examples for the main methods available in the Agents class. Additional methods and their usage can be added following the same structure.
Run an agent.
-
agentId
:string
- The ID of the agent to run. -
executionId
:string
- The execution ID of the agent to run. -
params
:RunAgentParams
- An object containing the parameters for running the agent. -
options
:CallOptions
(optional) - Additional options for the API call.
await agents.runAgent(
'agent-id',
'execution-id',
{
history: []
}
)
// example response
{
"data": {
"say": {
"action": "say",
"input": {
"message": "Some message"
}
}
}
}
Find templates with optional pagination and query.
-
params
:FindTemplatesOptions
(optional) - Optional find parameters.
const templatesList = await agents.findTemplates({
query: 'search query',
size: 10,
from: 0,
});
// Example response
{
items: [
{
id: 'template-id',
name: 'Template Name',
description: 'Template Description',
// ...other properties
},
// ...more templates
],
total: 1
}
Get a template by its ID.
-
templateId
:string
- The ID of the template to retrieve.
const template = await agents.getTemplate('template-id');
Create a new template.
-
params
:CreateTemplateParams
- An object containing the properties of the template to create.
const newTemplate = await agents.createTemplate({
agentId: 'agent-id',
flowIds: ['flow-id-1', 'flow-id-2'],
});
Delete a template by its ID.
-
templateId
:string
- The ID of the template to delete.
await agents.deleteTemplate('template-id');