Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools_agent #891

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llm_agents/tools_agent/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 160
}
82 changes: 82 additions & 0 deletions llm_agents/tools_agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

# @graphai/tools_agent for GraphAI

General tools agents

### Install

```sh
yarn add @graphai/tools_agent
```


### Usage

```typescript
import { GraphAI } from "graphai";
import { toolsAgent } from "@graphai/tools_agent";

const agents = { toolsAgent };

const graph = new GraphAI(graph_data, agents);
const result = await graph.run();
```

### Agents description
- toolsAgent -

### Input/Output/Params Schema & samples
- [toolsAgent](https://github.com/receptron/graphai/blob/main/docs/agentDocs/undefined/toolsAgent.md)

### Input/Params example
- toolsAgent

```typescript
{
"inputs": {
"llmAgent": "openAIAgent",
"tools": [
{
"type": "function",
"function": {
"name": "lightAgent--toggleLight",
"description": "Switch of light",
"parameters": {
"type": "object",
"properties": {
"switch": {
"type": "boolean",
"description": "change light state"
}
}
}
}
}
],
"messages": [
{
"role": "system",
"content": "You are a light switch. Please follow the user's instructions."
}
],
"userInput": {
"text": "turn on the light.",
"message": {
"role": "user",
"content": "turn on the light."
}
}
},
"params": {}
}
```










11 changes: 11 additions & 0 deletions llm_agents/tools_agent/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import eslintBase from "../../config/eslint.config.base.mjs";

export default [
{
files: ["{src,test,samles}/**/*.{js,ts,yaml,yml,json}"],
},
{
ignores: ["lib/**/*", "*.ts", "apiDoc/**/*", "apiDoc/*"],
},
...eslintBase,
];
2 changes: 2 additions & 0 deletions llm_agents/tools_agent/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import toolsAgent from "./tools_agent";
export { toolsAgent };
8 changes: 8 additions & 0 deletions llm_agents/tools_agent/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolsAgent = void 0;
const tools_agent_1 = __importDefault(require("./tools_agent"));
exports.toolsAgent = tools_agent_1.default;
47 changes: 47 additions & 0 deletions llm_agents/tools_agent/lib/tools_agent.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
declare const toolsAgentInfo: {
name: string;
agent: (context: import("graphai").AgentFunctionContext) => Promise<any>;
mock: (context: import("graphai").AgentFunctionContext) => Promise<any>;
samples: {
inputs: {
llmAgent: string;
tools: {
type: string;
function: {
name: string;
description: string;
parameters: {
type: string;
properties: {
switch: {
type: string;
description: string;
};
};
};
};
}[];
messages: {
role: string;
content: string;
}[];
userInput: {
text: string;
message: {
role: string;
content: string;
};
};
};
params: {};
result: string;
}[];
description: string;
category: never[];
author: string;
repository: string;
tools: never[];
license: string;
hasGraphData: boolean;
};
export default toolsAgentInfo;
127 changes: 127 additions & 0 deletions llm_agents/tools_agent/lib/tools_agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const nested_agent_1 = require("@graphai/vanilla/lib/graph_agents/nested_agent");
const toolWorkFlowStep = {
version: 0.5,
nodes: {
llm: {
agent: ":llmAgent",
isResult: true,
params: {
forWeb: true,
stream: true,
tools: ":tools",
},
inputs: { messages: ":messages", prompt: ":userInput.text" },
},
textMessage: {
unless: ":llm.tool.id",
agent: "copyAgent",
inputs: {
messages: [":userInput.message", { role: "assistant", content: ":llm.message.content" }],
},
},
tool_calls: {
if: ":llm.tool_calls",
agent: "mapAgent",
inputs: { rows: ":llm.tool_calls" },
params: {
compositeResult: true,
},
graph: {
version: 0.5,
nodes: {
tool: {
agent: ":row.name.split(--).$0",
inputs: {
arg: ":row.arguments",
func: ":row.name.split(--).$1",
tool_call: ":row",
},
},
message: {
isResult: true,
agent: "copyAgent",
inputs: {
role: "tool",
tool_call_id: ":row.id",
name: ":row.name",
content: ":tool.result",
},
},
},
},
},
toolsMessage: {
agent: "pushAgent",
inputs: {
array: [":userInput.message", ":llm.message"],
items: ":tool_calls.message",
},
},
buffer: {
agent: "copyAgent",
anyInput: true,
inputs: { array: [":textMessage.messages", ":toolsMessage.array"] },
},
reducer: {
isResult: true,
agent: "pushAgent",
inputs: { array: ":messages", items: ":buffer.array.$0" },
},
},
};
const toolsAgent = (0, nested_agent_1.nestedAgentGenerator)(toolWorkFlowStep);
const toolsAgentInfo = {
name: "toolsAgent",
agent: toolsAgent,
mock: toolsAgent,
samples: [
{
inputs: {
llmAgent: "openAIAgent",
tools: [
{
type: "function",
function: {
name: "lightAgent--toggleLight",
description: "Switch of light",
parameters: {
type: "object",
properties: {
switch: {
type: "boolean",
description: "change light state",
},
},
},
},
},
],
messages: [
{
role: "system",
content: "You are a light switch. Please follow the user's instructions.",
},
],
userInput: {
text: "turn on the light.",
message: {
role: "user",
content: "turn on the light.",
},
},
},
params: {},
result: "",
},
],
description: "",
category: [],
author: "",
repository: "",
tools: [],
license: "",
hasGraphData: true,
};
exports.default = toolsAgentInfo;
36 changes: 36 additions & 0 deletions llm_agents/tools_agent/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@graphai/tools_agent",
"version": "0.2.0",
"description": "General tools agents",
"main": "lib/index.js",
"files": [
"./lib"
],
"scripts": {
"build": "rm -r lib/* && tsc && tsc-alias",
"eslint": "eslint",
"format": "prettier --write '{src,tests,samples}/**/*.ts'",
"doc": "npx agentdoc",
"examplesDoc": "npx ts-node -r tsconfig-paths/register tests/examples.ts",
"test": "echo nothing",
"test_run": "node --test -r tsconfig-paths/register --require ts-node/register ./tests/run_*.ts # just run locally",
"chat": "node -r tsconfig-paths/register -r ts-node/register ./tests/chat_dispatch.ts",
"b": "yarn run format && yarn run eslint && yarn run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/receptron/graphai"
},
"author": "Satoshi Nakajima, Isamu Arimoto",
"license": "MIT",
"bugs": {
"url": "https://github.com/receptron/graphai/issues"
},
"homepage": "https://github.com/receptron/graphai/blob/main/llm_agents/tools_agent/README.md",
"dependencies": {},
"devDependencies": {},
"types": "./lib/index.d.ts",
"directories": {
"lib": "lib"
}
}
3 changes: 3 additions & 0 deletions llm_agents/tools_agent/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import toolsAgent from "./tools_agent";

export { toolsAgent };
Loading
Loading