Skip to content

Commit d789ce7

Browse files
Merge pull request #129 from restackio/reactflowLint
Reactflow lint
2 parents a5b8995 + 472fe5d commit d789ce7

24 files changed

+188
-215
lines changed

agent-reactflow/README.md

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
A sample repository to have low code editor with React Flow of Agents built with Restack.
44

5+
See the full documentation on our [Agent with React Flow](https://docs.restack.io/blueprints/agent-reactflow) page.
6+
57
### Apps
68

7-
- `frontend`: another [Next.js](https://nextjs.org/) app
9+
- `frontend`: a [Next.js](https://nextjs.org/) app
810
- `backend`: a [Restack](https://restack.io/) app
911

1012
## Requirements
@@ -27,11 +29,91 @@ pnpm i
2729
pnpm run dev
2830
```
2931

30-
Leveraging turborepo, this will start both frontend and backend.
32+
Leveraging TurboRepo, this will start both frontend and backend.
3133
Your code will be running and syncing with Restack to execute agents.
3234

3335
## Run agents
3436

35-
### from frontend
37+
### From frontend
38+
39+
![Run agents from frontend](./agent-reactflow.png)
40+
41+
### from UI
42+
43+
You can run agents from the UI by clicking the "Run" button.
44+
45+
![Run agents from UI](./agent-post.png)
46+
47+
### from API
48+
49+
You can run agents from the API by using the generated endpoint:
50+
51+
`POST http://localhost:6233/api/agents/agentFlow`
52+
53+
### from any client
54+
55+
You can run agents with any client connected to Restack, for example:
56+
57+
```bash
58+
pnpm schedule-agent
59+
```
60+
61+
executes `scheduleAgent.ts` which will connect to Restack and execute the `agentFlow` agent.
62+
63+
## Send events to the Agent
64+
65+
### from Backend Developer UI
66+
67+
You can send events like or end from the UI.
68+
69+
![Send events from UI](./agent-event.png)
70+
71+
And see the events in the run:
72+
73+
![See events in UI](./agent-run.png)
74+
75+
### from API
76+
77+
You can send events to the agent by using the following endpoint:
78+
79+
`PUT http://localhost:6233/api/agents/agentFlow/:agentId/:runId`
80+
81+
with the payload:
82+
83+
```json
84+
{
85+
"name": "idVerification",
86+
"input": {
87+
"type": "id",
88+
"documentNumber": "1234567890"
89+
}
90+
}
91+
```
92+
93+
to send messages to the agent.
94+
95+
or
96+
97+
```json
98+
{
99+
"eventName": "end"
100+
}
101+
```
102+
103+
to end the conversation with the agent.
104+
105+
### from any client
106+
107+
You can send event to the agent with any client connected to Restack, for example:
108+
109+
Modify agentId and runId in eventAgent.ts and then run:
110+
111+
```bash
112+
pnpm event-agent
113+
```
114+
115+
It will connect to Restack and send an events to the agent.
116+
117+
## Deploy on Restack Cloud
36118

37-
![Run agents from frontend](./agent-reactflow.png)
119+
To deploy the application on Restack, you can create an account at [https://console.restack.io](https://console.restack.io)

agent-reactflow/agent-event.png

73.2 KB
Loading

agent-reactflow/agent-post.png

53 KB
Loading

agent-reactflow/agent-run.png

486 KB
Loading
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.env
22
node_modules
33
media
4-
dist
4+
dist
5+
.eslintcache
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { config } from "@agent-reactflow/eslint-config/base";
2+
3+
/** @type {import("eslint").Linter.Config} */
4+
export default config;

agent-reactflow/apps/backend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"start": "tsx src/services.ts",
88
"start.watch": "nodemon src/services.ts",
99
"dev": "open-cli http://localhost:5233 && tsx watch --include src src/services.ts",
10+
"lint": "eslint src --fix --max-warnings 0 --cache",
1011
"build": "tsc --build",
1112
"clean": "rm -rf node_modules",
1213
"workflow": "tsx ./scheduleWorkflow.ts",
13-
"event": "tsx ./eventAgent.ts",
14-
"restack-up": "node restack_up.mjs"
14+
"event": "tsx ./eventAgent.ts"
1515
},
1616
"dependencies": {
1717
"@restackio/ai": "^0.0.119",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { client } from "./src/client";
2+
3+
export type InputSchedule = {
4+
name: string;
5+
};
6+
7+
async function scheduleAgent(input: InputSchedule) {
8+
try {
9+
const agentId = `${Date.now()}-agentFlow`;
10+
const runId = await client.scheduleAgent({
11+
agentName: "agentFlow",
12+
agentId,
13+
input,
14+
});
15+
16+
const result = await client.getAgentResult({ agentId, runId });
17+
18+
console.log("Agent result:", result);
19+
20+
process.exit(0); // Exit the process successfully
21+
} catch (error) {
22+
console.error("Error scheduling agent:", error);
23+
process.exit(1); // Exit the process with an error code
24+
}
25+
}
26+
27+
scheduleAgent({
28+
name: "test",
29+
});

agent-reactflow/apps/backend/src/agents/chat.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
condition,
55
log,
66
step,
7-
sleep,
87
} from "@restackio/ai/agent";
98
import * as functions from "../functions";
109

@@ -17,11 +16,12 @@ type AgentChatOutput = {
1716

1817
export async function agentChat(): Promise<AgentChatOutput> {
1918
let endReceived = false;
20-
let messages: functions.Message[] = [];
19+
const messages: functions.Message[] = [];
2120

22-
onEvent(messagesEvent, async ({ messages, stream = true }: { messages: functions.Message[], stream?: boolean }) => {
21+
onEvent(messagesEvent, async ({ messages, tools, stream = true }: { messages: functions.Message[], tools: any, stream?: boolean }) => {
2322
const result = await step<typeof functions>({}).llmChat({
2423
messages,
24+
tools,
2525
stream
2626
});
2727
messages.push(result);

agent-reactflow/apps/backend/src/agents/flow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type AgentFlowOutput = {
4444
}
4545
export async function agentFlow({flowJson}: AgentFlowInput): Promise<AgentFlowOutput> {
4646
let endReceived = false;
47-
let eventResults: AgentFlowOutput['results'] = []
47+
const eventResults: AgentFlowOutput['results'] = []
4848

4949
try {
5050

0 commit comments

Comments
 (0)