You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/game_sdk/hosted_game/README.md
+57-10Lines changed: 57 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,12 @@
3
3
This is a Python SDK for the Virtuals Twitter Agent. It allows you to configure and deploy agents that can interact with the Twitter/X platform. This SDK/API allows you to configure your agents powered by the GAME architecture. This is similar to configuring your agent in the [Agent Sandbox](https://game-lite.virtuals.io/) on the [Virtuals Platform](https://app.virtuals.io/).
4
4
5
5
## Create an API key
6
+
6
7
Open the [Virtuals Platform](https://app.virtuals.io/) and create/get an API key from the Agent Sandbox by clicking `SDK/API Access`
7
8
8
9

9
10
10
-
Store the key in a safe location, like a `.bashrc` or a `.zshrc` file.
11
+
Store the key in a safe location, like a `.bashrc` or a `.zshrc` file.
Alternatively, you can also use a `.env` file ([`python-dotenv` package](https://github.com/theskumar/python-dotenv) to store and load the key) if you are using the Virtuals Python SDK.
17
18
18
19
## Usage (GAME)
20
+
19
21
The Virtuals SDK current main functionalities are to develop and configure agents powered by GAME. Other functionalities to interact with the Virtuals Platform will be supported in the future. This GAME SDK can be used for multiple use cases:
20
22
21
23
1. Develop, evaluate and update the existing Agent in Twitter environment.
22
-
2. Build on other platforms and application using GAME (Task-based Agent).
24
+
2. Build on other platforms and application using GAME (Task-based Agent).
23
25
24
26
### Update the existing Agent in Twitter environment
27
+
25
28
The SDK provides another interface to configure agents that is more friendly to developers rather than through a UI. This is similar to configuring your agent in the [Agent Sandbox](https://game-lite.virtuals.io/).
26
29
27
30
```python
28
31
from game_sdk.hosted_game.agent import Agent
29
32
33
+
34
+
30
35
# Create agent with just strings for each component
36
+
> [!NOTE]
37
+
> {{replyCount}} is a variable that will be replaced with the number of replies made by the agent. Only applicable for task_description.
38
+
31
39
agent = Agent(
32
40
api_key=VIRTUALS_API_KEY,
33
41
goal="Autonomously analyze crypto markets and provide trading insights",
34
42
description="HODL-9000: A meme-loving trading bot powered by hopium and ramen",
35
-
world_info="Virtual crypto trading environment where 1 DOGE = 1 DOGE"
43
+
world_info="Virtual crypto trading environment where 1 DOGE = 1 DOGE",
44
+
task_description="Process incoming tweet. Ignore if it is boring or unimportant. Total replies made: {{replyCount}}. Ignore if the conversation has gone too long."
36
45
)
37
46
```
38
-
You can also initialize the agent first with just the API key and set the goals, descriptions and world information separately and check the current agent descriptions if needed.
47
+
48
+
You can also initialize the agent first with just the API key andset the goals, descriptions and world information separately and check the current agent descriptions if needed.
39
49
40
50
```python
41
51
agent = Agent(api_key=VIRTUALS_API_KEY)
42
52
43
-
# check what is current goal, descriptionsand world_info
53
+
# check what is current goal, descriptions, world_info and task_description
44
54
agent.get_goal()
45
55
agent.get_description()
46
56
agent.get_world_info()
57
+
agent.get_task_description()
47
58
48
-
# Set components individually - set change the agent goal/description/worldinfo
59
+
# Set components individually - set change the agent goal/description/worldinfo/task_description
49
60
agent.set_goal("Autonomously analyze crypto markets and provide trading insights")
50
61
agent.set_description("HODL-9000: A meme-loving trading bot powered by hopium and ramen")
51
62
agent.set_world_info("Virtual crypto trading environment where 1 DOGE = 1 DOGE")
63
+
agent.set_task_description("Process incoming tweet. Ignore if it is boring or unimportant. Total replies made: {{replyCount}}. Ignore if the conversation has gone too long.")
52
64
53
-
# check what is current goal, descriptionsand world_info
65
+
# check what is current goal, descriptions, world_info and task_description
54
66
agent.get_goal()
55
67
agent.get_description()
56
68
agent.get_world_info()
69
+
agent.get_task_description()
70
+
71
+
# Set heartbeat
72
+
agent.set_main_heartbeat(15)
73
+
agent.set_reaction_heartbeat(5)
74
+
75
+
# check what is current heartbeat
76
+
agent.get_main_heartbeat()
77
+
agent.get_reaction_heartbeat()
78
+
```
79
+
80
+
### Worker
81
+
82
+
You can add a worker to the agent. This is useful if you want to run a function on a specific worker.
83
+
84
+
```python
85
+
agent.add_worker(Worker(name="worker-twitter", description="worker for twitter", environment={"NODE_ENV": "production"}))
57
86
```
58
87
59
88
### Functions
89
+
60
90
By default, there are no functions enabled when the agent is initialized (i.e. the agent has no actions/functions it can execute). There are a list of available and provided functions for the Twitter/X platform and you can set them.
You can then equip the agent with some custom functions. Because the agent is hosted, custom functions need to be wrapped inAPI calls and can then be defined as follows:
worker= Worker( # you can link a worker to the function
121
+
name="worker custom search internet",
122
+
description="worker for custom search internet",
123
+
environment={"NODE_ENV": "production"}
124
+
)
89
125
)
90
126
91
127
# adding custom functions only for platform twitter
92
128
agent.add_custom_function(search_function)
93
129
```
94
130
95
131
### Evaluate with Simulate, Deploy
132
+
96
133
You can simulate one step of the agentic loop on Twitter/X with your new configurations and see the outputs. This is similar to the simulate button on the [Agent Sandbox](https://game-lite.virtuals.io/).
97
134
98
135
```python
99
136
# Simulate one step of the full agentic loop on Twitter/X from the HLP -> LLP -> action (NOTE: supported for Twitter/X only now)
To more realistically simulate deployment, you can also run through the simulate function with the same session idfor a number of steps.
103
141
104
142
```python
@@ -118,13 +156,15 @@ response = agent.react(
118
156
```
119
157
120
158
Once you are happy, `deploy_twitter` will push your agent configurations to production and run your agent on Twitter/X autonomously.
159
+
121
160
```python
122
161
# deploy agent! (NOTE: supported for Twitter/X only now)
123
162
agent.deploy_twitter()
124
163
```
125
164
126
165
## Build on other platforms using GAME
127
-
`simulate_twitter` and `deploy_twitter` runs through the entire GAME stack from HLP → LLP→ action/function selected. However, these agent functionalities are currently for the Twitter/X platform. You may utilize Task-based Agent with Low-Level Planner and Reaction Module to develop applications that are powered by GAME. The Low Level Planner (LLP) of the agent (please see [documentation](https://www.notion.so/1592d2a429e98016b389ea26b53686a3?pvs=21) for more details on GAME and LLP) can separately act as a decision making engine based on a task description and event occurring. This agentic architecture is simpler but also sufficient for many applications.
166
+
167
+
`simulate_twitter`and`deploy_twitter` runs through the entire GAME stack fromHLP → LLP→ action/function selected. However, these agent functionalities are currently for the Twitter/X platform. You may utilize Task-based Agent with Low-Level Planner and Reaction Module to develop applications that are powered by GAME. The Low Level Planner (LLP) of the agent (please see [documentation](https://www.notion.so/1592d2a429e98016b389ea26b53686a3?pvs=21) for more details on GAMEandLLP) can separately act as a decision making engine based on a task description and event occurring. This agentic architecture is simpler but also sufficient for many applications.
128
168
129
169
We are releasing this simpler setup as a more generalised/platform agnostic framework (not specific to Twitter/X). The entire GAME stack along with the HLP will be opened up to be fully configurable and platform agnostic in the coming weeks.
130
170
@@ -150,19 +190,23 @@ response = agent.react(
150
190
## Arguments Definition
151
191
152
192
### Session ID
153
-
The session ID is an identifier for an instance of the agent. When using the same session ID, it maintains and picks up from where it last left off, continuing the session/instance. It should be split per user/ conversation that you are maintaining on your platform. For different platforms, different session ID can be used.
193
+
194
+
The session IDis an identifier for an instance of the agent. When using the same session ID, it maintains and picks up from where it last left off, continuing the session/instance. It should be split per user/ conversation that you are maintaining on your platform. For different platforms, different session ID can be used.
154
195
155
196
### Platform Tag
197
+
156
198
When adding custom functions, and when calling the react agent (i.e. LLP), there is a platform tag that can be defined. This acts like a filterfor the functions available that is passed to the agent. You should define the platform when passing in the events.
157
199
158
200
### Task Description
201
+
159
202
Task description serves as the prompt for the agent to respond. Since the reaction can be platform-based, you can define task description based on the platforms. In the task description, you should passinany related info that require agent to make decision. That should include:
203
+
160
204
- User message
161
205
- Conversation history
162
206
- Instructions
163
207
164
-
165
208
## Importing Functions and Sharing Functions
209
+
166
210
With this SDKand function structure, importing and sharing functions is also possible. Looking forward to all the different contributions and functionalities we will build together as a community!
0 commit comments