Skip to content

Commit 015609f

Browse files
committed
prepare for restack 57
1 parent 97cc97c commit 015609f

File tree

12 files changed

+88
-72
lines changed

12 files changed

+88
-72
lines changed

agent_chat/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ You can run workflows from the UI by clicking the "Run" button.
4848

4949
You can run workflows from the API by using the generated endpoint:
5050

51-
`POST http://localhost:6233/api/workflows/AgentWorkflow`
51+
`POST http://localhost:6233/api/agents/AgentChat`
5252

5353
### from any client
5454

@@ -58,7 +58,7 @@ You can run workflows with any client connected to Restack, for example:
5858
poetry run schedule
5959
```
6060

61-
executes `schedule_workflow.py` which will connect to Restack and execute the `AgentWorkflow` workflow.
61+
executes `schedule_agent.py` which will connect to Restack and execute the `AgentChat` agent.
6262

6363
## Send events to the Agent
6464

@@ -76,7 +76,7 @@ And see the events in the run:
7676

7777
You can send events to the agent by using the following endpoint:
7878

79-
`PUT http://localhost:6233/api/workflows/AgentWorkflow/:workflowId/:runId`
79+
`PUT http://localhost:6233/api/agents/AgentChat/:agentId/:runId`
8080

8181
with the payload:
8282

agent_chat/event_agent.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import asyncio
2+
from restack_ai import Restack
3+
async def main(agent_id:str,run_id:str):
4+
5+
client = Restack()
6+
7+
await client.send_agent_event(
8+
agent_id=agent_id,
9+
run_id=run_id,
10+
event_name="message",
11+
event_input={"content": "Tell me another joke"}
12+
)
13+
14+
await client.send_agent_event(
15+
agent_id=agent_id,
16+
run_id=run_id,
17+
event_name="end",
18+
)
19+
20+
exit(0)
21+
22+
def run_event_agent():
23+
asyncio.run(main(agent_id="your-agent-id", run_id="your-run-id"))
24+
25+
if __name__ == "__main__":
26+
run_event_agent()

agent_chat/event_workflow.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

agent_chat/pyproject.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ packages = [{include = "src"}]
1313
python = ">=3.10,<4.0"
1414
watchfiles = "^1.0.0"
1515
pydantic = "^2.10.4"
16-
17-
# Build system configuration
1816
openai = "^1.60.2"
19-
restack-ai = "^0.0.55"
17+
restack-ai = "^0.0.57"
2018

2119
[build-system]
2220
requires = ["poetry-core"]
@@ -26,5 +24,5 @@ build-backend = "poetry.core.masonry.api"
2624
[tool.poetry.scripts]
2725
dev = "src.services:watch_services"
2826
services = "src.services:run_services"
29-
schedule = "schedule_workflow:run_schedule_workflow"
30-
event = "event_workflow:run_event_workflow"
27+
schedule = "schedule_agent:run_schedule_agent"
28+
event = "event_agent:run_event_agent"
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import asyncio
22
import time
33
from restack_ai import Restack
4-
from src.workflows.workflow import AgentChatInput
4+
from agent_chat.src.agents.agent import AgentChatInput
55
async def main():
66

77
client = Restack()
88

99
workflow_id = f"{int(time.time() * 1000)}-AgentChat"
10-
run_id = await client.schedule_workflow(
11-
workflow_name="AgentChat",
12-
workflow_id=workflow_id,
10+
run_id = await client.schedule_agent(
11+
agent_name="AgentChat",
12+
agent_id=workflow_id,
1313
input=AgentChatInput(message="Tell me a joke")
14-
)
14+
)
1515

16-
await client.get_workflow_result(
17-
workflow_id=workflow_id,
16+
await client.get_agent_result(
17+
agent_id=workflow_id,
1818
run_id=run_id
1919
)
2020

2121
exit(0)
2222

23-
def run_schedule_workflow():
23+
def run_schedule_agent():
2424
asyncio.run(main())
2525

2626
if __name__ == "__main__":
27-
run_schedule_workflow()
27+
run_schedule_agent()

agent_chat/src/workflows/workflow.py renamed to agent_chat/src/agents/agent.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import timedelta
22
from typing import List
33
from pydantic import BaseModel
4-
from restack_ai.workflow import workflow, import_functions, log
4+
from restack_ai.workflow import agent, import_functions, log
55

66
with import_functions():
77
from src.functions.llm_chat import llm_chat, LlmChatInput, Message
@@ -12,26 +12,26 @@ class MessageEvent(BaseModel):
1212
class EndEvent(BaseModel):
1313
end: bool
1414

15-
@workflow.defn()
15+
@agent.defn()
1616
class AgentChat:
1717
def __init__(self) -> None:
1818
self.end = False
1919
self.messages = []
20-
@workflow.event
20+
@agent.event
2121
async def message(self, message: MessageEvent) -> List[Message]:
2222
log.info(f"Received message: {message.content}")
2323
self.messages.append({"role": "user", "content": message.content})
24-
assistant_message = await workflow.step(llm_chat, LlmChatInput(messages=self.messages), start_to_close_timeout=timedelta(seconds=120))
24+
assistant_message = await agent.step(llm_chat, LlmChatInput(messages=self.messages), start_to_close_timeout=timedelta(seconds=120))
2525
self.messages.append(assistant_message)
2626
return self.messages
27-
@workflow.event
27+
@agent.event
2828
async def end(self, end: EndEvent) -> EndEvent:
2929
log.info(f"Received end")
3030
self.end = True
3131
return end
32-
@workflow.run
32+
@agent.run
3333
async def run(self, input: dict):
34-
await workflow.condition(
34+
await agent.condition(
3535
lambda: self.end
3636
)
3737
return

agent_chat/src/services.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import os
33
from src.functions.llm_chat import llm_chat
44
from src.client import client
5-
from src.workflows.workflow import AgentChat
5+
from agent_chat.src.agents.agent import AgentChat
66
from watchfiles import run_process
77
import webbrowser
88

99
async def main():
1010

1111
await client.start_service(
12-
workflows=[AgentChat],
12+
agents=[AgentChat],
1313
functions=[llm_chat]
1414
)
1515

agent_tool/README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Restack AI - Agent Tool
22

33
This repository contains a tool for an AI agent.
4-
It demonstrates how to set up a basic workflow and functions.
4+
It demonstrates how to set up a basic agent with functions calling.
55

6-
Follow [the step-by-step tutorial](https://docs.restack.io/examples/projects/agent#tutorial) on how to customize the agent tool example/
6+
Follow [the step-by-step tutorial](https://docs.restack.io/examples/projects/agent#tutorial) on how to customize the agent tool example/
77

88
## Prerequisites
99

@@ -44,24 +44,27 @@ Duplicate the `env.example` file and rename it to `.env`.
4444

4545
Obtain a Restack API Key to interact with the 'restack-c1' model at no cost from [console.restack.io](https://console.restack.io)
4646

47-
## Run workflows
47+
## Run agents
4848

4949
### from UI
5050

51-
You can run workflows from the UI by clicking the "Run" button.
51+
You can run agents from the UI by clicking the "Run" button.
5252

53-
![Run workflows from UI](./screenshot-endpoints.png)
53+
![Run agents from UI](./screenshot-endpoints.png)
5454

5555
### from API
5656

57-
You can run workflows from the API by using the generated endpoint:
57+
You can run agents from the API by using the generated endpoint:
5858

59-
`POST http://localhost:6233/api/workflows/AgentChatToolFunctions`
59+
`POST http://localhost:6233/api/agents/AgentChatToolFunctions`
60+
61+
## Send an event to the agent
62+
63+
### from UI
6064

61-
## Send an event to the
6265
```
6366
{
64-
"workflowId": "{workflow_id}",
67+
"agentId": "{agent_id}",
6568
"runId": "{run_id}",
6669
"eventName": "message",
6770
"eventInput": {
@@ -70,6 +73,21 @@ You can run workflows from the API by using the generated endpoint:
7073
}
7174
```
7275

76+
You can send events to the agent by using the generated endpoint:
77+
78+
`PUT http://localhost:6233/api/agents/AgentChatToolFunctions/:agentId/:runId`
79+
80+
and the payload:
81+
82+
```
83+
{
84+
"eventName": "message",
85+
"eventInput": {
86+
"content": "What clothes are currently on sales?"
87+
}
88+
}
89+
```
90+
7391
Now, you can simply trigger more events from the Developer UI by clicking in the timeline on 'Send again' for the event and change the payload.
7492

7593
![Send another message from UI](./event-send-again.png)

agent_tool/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ requests = "2.32.3"
1717

1818
# Build system configuration
1919
openai = "^1.60.2"
20-
restack-ai = "^0.0.55"
20+
restack-ai = "^0.0.57"
2121
[build-system]
2222
requires = ["poetry-core"]
2323
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)