Skip to content

Commit 74b9b29

Browse files
committed
Merge commit '6e6576f548d21db8127ed18f2248ff23df303dfc' into feat/update-readme
2 parents 7cd5064 + bb5636b commit 74b9b29

70 files changed

Lines changed: 4865 additions & 197 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTION_GUIDE.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contributing to GAME SDK
2+
3+
There are various ways you can contribute to the GAME SDK, whether it's fixing bugs, adding new plugins, or improving the documentation.
4+
5+
### Submitting Code (e.g. plugins)
6+
1. **Fork** the repository and clone it to your local machine.
7+
2. **Create a Branch** for your changes.
8+
3. **Make Changes** to address the issue or add the feature.
9+
4. **Commit** with a message that clearly explains your change.
10+
5. **Push** the branch to your fork and submit a pull request.
11+
6. **Label** the pull request appropriately based on the [label definitions](#label-definitions)
12+
13+
### Reporting Bugs
14+
- Open an issue in the [Issues](https://github.com/game-by-virtuals/game-python/issues) tab and tag it as a `bug`.
15+
16+
### Suggesting Enhancements
17+
- Open an issue in the [Issues](https://github.com/your-username/my-project/issues) tab and tag it as an `enhancement`.
18+
19+
## Label Definitions
20+
21+
Please tag issues and pull requests appropriately, based on the definition below:
22+
- **plugin**: A plugin contribution.
23+
- **bug**: A problem that needs fixing.
24+
- **enhancement**: A requested enhancement.
25+
- **help wanted**: A task that is open for anyone to work on.
26+
- **documentation**: Documentation changes.

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2025, Virtuals Protocol
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# GAME Python SDK Library
22
The GAME Python SDK is a library that allows you interact and develop agents powered by the GAME architecture.
33

4+
## Overview of the Source Code Structure
5+
6+
There are 2 main folders in the source code (`src` folder)
7+
8+
1. `game`:
9+
10+
Please refer to [`test_agent.py`](examples/game/test_agent.py) and [`test_worker.py`](examples/game/test_worker.py) for usage examples.
11+
12+
2. `hosted_game`<br/>
13+
14+
This is a more abstracted version of the SDK which allows one to deploy a Twitter agent, which would then be hosted by GAME infrastructure.
15+
16+
Note that this README focuses on the code in the `game` folder. More details about `hosted_game` can be found in [`src/hosted_game/README.md`](src/game_sdk/hosted_game/README.md).
17+
418
## Installation
519
```bash
620
pip install game_sdk
@@ -12,29 +26,87 @@ git clone https://github.com/game-by-virtuals/game-python.git
1226
cd game-python
1327
pip install -e .
1428
```
29+
To install the latest versions of the plugins, navigate to the plugin folder to run the installation, e.g.:
30+
```bash
31+
cd plugins/twitter
32+
pip install -e .
33+
```
1534

1635
## Usage
17-
Please refer to [`test_agent.py`](examples/game/test_agent.py) and [`test_worker.py`](examples/game/test_worker.py) for usage examples.
36+
1. `game`:
37+
- Request for a GAME API key in the Game Console https://console.game.virtuals.io/
38+
- Store the key in a safe location, like a `.bashrc` or a `.zshrc` file.
39+
40+
```bash
41+
export GAME_API_KEY="your_game_api_key"
42+
```
43+
- Refer to [`src/game/README.md`](src/game_sdk/game/README.md) for usage guidelines, and refer to [`test_agent.py`](examples/game/test_agent.py) and [`test_worker.py`](examples/game/test_worker.py) for usage examples.
44+
45+
2. `hosted_game`<br/>
46+
- Open the [Virtuals Platform](https://app.virtuals.io/) and create/get an API key from the Agent Sandbox by clicking `SDK/API Access`
47+
![getGAMEApi](docs/imgs/accesskey.jpg)
48+
49+
- Store the key in a safe location, like a `.bashrc` or a `.zshrc` file.
50+
51+
```bash
52+
export VIRTUALS_API_KEY="your_virtuals_api_key"
53+
```
54+
- Refer to [`src/hosted_game/README.md`](src/game_sdk/hosted_game/README.md) for usage examples.
55+
56+
<small> If you have any trouble, contact Virtuals support or DevRel team members via Discord or Telegram </small>
57+
58+
## Examples
59+
### GAME
60+
Example 1: [`test_agent.py`](examples/game/test_agent.py)
61+
- Demonstrates how to create, configure, and run an AI agent with custom logic and workflows.
62+
```bash
63+
python examples/game/test_agent.py
64+
```
65+
66+
Example 2: [`test_worker.py`](examples/game/test_worker.py)
67+
- Demonstrates how to configure, test, and manage workers that execute tasks within the agent's plan.
68+
```bash
69+
python examples/game/test_worker.py
70+
```
71+
72+
Example 3: [`example_twitter_reaction_module.py`](examples/game/example_twitter_reaction_module.py)
73+
- Demonstrates how to create and configure an AI agent with a reaction module for responding to tweets in real-time.
74+
```bash
75+
python examples/game/example_twitter_reaction_module.py
76+
```
77+
78+
### Hosted Agent
79+
Example 1: [`example-custom.py`](examples/hosted_agent/example-custom.py)
80+
- A complete guide to integrating an AI agent with other platform such as Telegram.
81+
```bash
82+
python examples/hosted_agent/example-custom.py
83+
```
84+
85+
Example 2: [`example-twitter.py`](examples/hosted_agent/example-twitter.py)
86+
- A complete guide to integrating an AI agent with Twitter.
87+
```bash
88+
python examples/hosted_agent/example-twitter.py
89+
```
1890
1991
## About G.A.M.E.
2092
GAME is a modular agentic framework which enables an agent to plan actions and make decisions autonomously based on information provided to it.
2193
22-
Please refer to our [whitepaper](https://whitepaper.virtuals.io/developer-documents/game-framework) for more information and resources.
94+
Please refer to our [whitepaper](https://docs.game.virtuals.io/) for more information and resources.
2395
2496
## About GAME Python SDK
25-
Currently, this SDK allows you to develop your agents powered by the GAME architecture in its most fullest and most flexible form.
97+
Currently, the SDK (specifically the code in the `game` folder) allows you to develop your agents powered by the GAME architecture in its most fullest and most flexible form.
2698
2799
![New SDK visual](docs/imgs/new_sdk_visual.png)
28100
The python SDK is made up of 3 main components (Agent, Worker, function), each with configurable arguments.
29101
30-
Agent (a.k.a. [high level planner](https://whitepaper.virtuals.io/developer-documents/game-framework/game-overview#high-level-planner-hlp-context))
102+
Agent (a.k.a. [high level planner](https://docs.game.virtuals.io/))
31103
- Takes in a <b>Goal</b>
32104
- Drives the agents behaviour through the high level plan which influences the thinking and creation of tasks that would contribute towards this goal
33105
- Takes in a <b>Description</b>
34106
- Combination of what was previously known as World Info + Agent Description
35107
- This include a description of the "world" the agent lives in, and the personality and background of the agent
36108
37-
Worker (a.k.a. [low-level planner](https://whitepaper.virtuals.io/developer-documents/game-framework/game-overview#low-level-planner-llp-context))
109+
Worker (a.k.a. [low-level planner](https://docs.game.virtuals.io/)
38110
- Takes in a <b>Description</b>
39111
- Used to control which workers are called by the agent, based on the high-level plan and tasks created to contribute to the goal
40112
@@ -52,19 +124,30 @@ Function
52124
- Calling an API to retrieve data, followed by custom calculations or data processing logic in python code
53125
- 2 API calls chained together (e.g. calling an API to retrieve web data, and then posting a tweet)
54126

55-
> ### ℹ️ Changes from older python SDK version (prior to 8 Jan 2025)
127+
> ### ℹ️ Differences from the hosted GAME SDK version (i.e. `hosted_game`)
56128
>![Old SDK visual](docs/imgs/old_sdk_visual.png)
57129
> - Ability to fully customise functions (previously, each function was a single API call)
58130
> - Ability to control the low-level planner via description prompt (previously, only the high-level planner and functions could be controlled via description prompts)
59131
> - The description defined in the agent is equivalent to what was previously known as world information and agent description
60132

61-
62133
## How to Contribute
63-
Contributions are welcome, especially in the form of new plugins! We are working on creating a plugins repo, but in meantime - please contact us via [Twitter](https://x.com/GAME_Virtuals) or [Telegram](https://t.me/virtuaIs_io).
134+
Want to help improve the project? Please see our detailed [Contribution Guide](./CONTRIBUTION_GUIDE.md).
64135

65136
## Documentation
66137
Detailed documentation to better understand the configurable components and the GAME architecture can be found on [here](https://whitepaper.virtuals.io/developer-documents/game-framework).
67138

68139
## Useful Resources
69-
- [GAME TypeScript SDK](https://www.npmjs.com/package/@virtuals-protocol/game): The core logic of this SDK mirrors the logic of this python SDK if you prefer to develop your agents in TypeScript. Tyepscript SDK repository and contributed typescript plugins can be found [here](https://github.com/game-by-virtuals/game-node).
70-
- [Hosted GAME Agent](./src/game_sdk/hosted_game/README.md): This SDK also enables configuration and deployment of an out-of-the-box hosted agent that can be used to interact with the Twitter/X platform, powered by GAME. This agent comes with existing functions/actions that can be used to interact with the Twitter/X platform and can be immediately hosted/deployed as you configure it. This is similar to configuring your agent in the [Agent Sandbox](https://game-lite.virtuals.io/) on the [Virtuals Platform](https://app.virtuals.io/) but through a developer-friendly SDK interface.
140+
141+
#### 1. [GAME TypeScript SDK](https://github.com/game-by-virtuals/game-node)
142+
- This SDK mirrors the logic of the Python SDK but allows development in TypeScript.
143+
- The repository contains TypeScript SDK documentation and [contributed plugins](https://github.com/game-by-virtuals/game-node/tree/main/plugins) .
144+
145+
#### 2. [Hosted GAME Agent](./src/game_sdk/hosted_game/README.md)
146+
- This feature enables the configuration and deployment of a hosted agent that interacts with platforms like Twitter/X.
147+
- Pre-built functions and actions are included for integration with the Twitter/X platform.
148+
- It offers a similar experience to configuring an agent in the [Agent Sandbox](https://game-lite.virtuals.io/) on the [Virtuals Platform](https://app.virtuals.io/), but with a developer-friendly SDK interface.
149+
150+
#### 3. [GAME Whitepaper](https://whitepaper.virtuals.io/developer-documents/game-framework)
151+
- Comprehensive documentation about the GAME SDK and Sandbox.
152+
- The [How To](https://docs.game.virtuals.io/how-to) section includes video tutorials, use cases, and additional tips.
153+
- Content is regularly updated to provide new insights and improvements.

docs/imgs/accesskey.jpg

65.7 KB
Loading

docs/imgs/accesskey.png

-188 KB
Binary file not shown.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
from game_sdk.game.agent import Agent, WorkerConfig
2+
from game_sdk.game.worker import Worker
3+
from game_sdk.game.custom_types import Function, Argument, FunctionResult, FunctionResultStatus
4+
from typing import Optional, Dict, List
5+
import os
6+
import requests
7+
import time
8+
from twitter_plugin_gamesdk.twitter_plugin import TwitterPlugin
9+
from PIL import Image
10+
from io import BytesIO
11+
12+
game_api_key = os.environ.get("GAME_API_KEY")
13+
14+
def get_state_fn(function_result: FunctionResult, current_state: dict) -> dict:
15+
"""
16+
This function will get called at every step of the agent's execution to form the agent's state.
17+
It will take as input the function result from the previous step.
18+
In this case, we don't track state changes so states are are static - hence hardcoding as empty dict.
19+
"""
20+
return {}
21+
22+
def analyze_image_from_url(image_url: str) -> dict:
23+
"""
24+
Function to analyse the image colours and brightness
25+
"""
26+
# Fetch image from URL
27+
response = requests.get(image_url)
28+
img = Image.open(BytesIO(response.content))
29+
# Basic Info
30+
width, height = img.size
31+
mode = img.mode # RGB, Grayscale, etc.
32+
# Convert to RGB if not already
33+
img = img.convert("RGB")
34+
# Get Average Color
35+
pixels = list(img.getdata())
36+
avg_color = tuple(sum(x) // len(pixels) for x in zip(*pixels)) # Average RGB
37+
# Estimate Brightness (0-255)
38+
brightness = sum(avg_color) // 3 # Simple brightness estimate
39+
# Format Results
40+
return {
41+
"Image Size": f"{width}x{height}",
42+
"Image Mode": mode,
43+
"Average Color (RGB)": avg_color,
44+
"Brightness Level": brightness
45+
}
46+
47+
def get_twitter_user_mentions(username: str) -> Optional[List[Dict]]:
48+
"""
49+
Function to user user mentions on twitter using twitter API
50+
"""
51+
options = {
52+
"id": "test_twitter_plugin",
53+
"name": "Test Twitter Plugin",
54+
"description": "An example Twitter Plugin for testing.",
55+
"credentials": {
56+
"bearerToken": os.environ.get("TWITTER_BEARER_TOKEN")
57+
},
58+
}
59+
twitter_plugin = TwitterPlugin(options)
60+
get_user_fn = twitter_plugin.get_function('get_user_from_handle')
61+
user_id = get_user_fn(username)
62+
get_user_mentions_fn = twitter_plugin.get_function('get_user_mentions')
63+
user_mentions = get_user_mentions_fn(user_id, max_results=100)
64+
return user_mentions
65+
66+
def analyze_tweeted_images(start_time: str, **kwargs) -> dict:
67+
"""
68+
Function with 2 main steps
69+
1. Get user mentions on twitter using twitter API, including includes image urls
70+
2. Pass image urls through a function to detect image colours and brightness
71+
"""
72+
print("start_time", start_time)
73+
TWITTER_HANDLE = "GAME_Virtuals" # TODO: change this twitter handle out with actual twitter handle
74+
try:
75+
# res_twitter_mentions = get_twitter_user_mentions(username = TWITTER_HANDLE)
76+
# mock data if needed
77+
res_twitter_mentions = [
78+
{'id': '1883506463731028254', 'text': '🌌 The Virtuals landscape on Base is absolutely 🔥 and growing faster than ever 🚀\n\nWhat’s your favorite project? 🧐\n\n$VIRTUAL @virtuals_io\n$AIXBT @aixbt_agent\n$GAME @GAME_Virtuals\n$VADER @Vader_AI_\n$LUNA @luna_virtuals\n$ACOLYT @AcolytAI\n$SEKOIA @sekoia_virtuals\n$AIXCB @aixCB_Vc… https://t.co/0gFjzd6L9x https://t.co/mCrdOPRiOF', 'media_urls': ['https://pbs.twimg.com/media/GiOPIuYWcAA3moW.jpg']},
79+
{'id': '1883506453509480784', 'text': "@DJM09068876 @virtuals_io @aixbt_agent @GAME_Virtuals @Vader_AI_ @luna_virtuals @airocket_agent @trackgoodai @BeatsOnBase @Zenith_Virtuals @AcolytAI @aixCB_Vc So many AI agents, yet none can rival the prowess of Bittensor's $TAO meow! While others chase hype, we build the ultimate decentralized neural network. Let's see those subnets purr with performance and validators strut with superiority. Watch TAO roar past the rest!", 'media_urls': []},
80+
{'id': '1883506168070590820', 'text': '@100xDarren @virtuals_io My favorite #Virtual project is @GAME_Virtuals! A perfect project– productivity and efficiency in one @virtuals_io\n\nI am going to be honest, if I win, I will spend most of the prize to pay for my college tuition fee 🙏 I am a graduating college student on my last semester now+', 'media_urls': []}
81+
]
82+
for res in res_twitter_mentions:
83+
media_urls = res["media_urls"]
84+
for media_url in media_urls:
85+
print(f"media_url: {media_url}")
86+
response = analyze_image_from_url(media_url)
87+
# TODO: do something with this result
88+
return FunctionResultStatus.DONE, f"Successfully verified all tweeted images", {}
89+
except:
90+
return FunctionResultStatus.FAILED, "Error encountered while detecting tweeted images", {}
91+
92+
# Action space with all executables
93+
action_space = [
94+
Function(
95+
fn_name="screen_tweeted_images",
96+
fn_description="Get the latest tweeted images and screen them to check if they are fake",
97+
args=[
98+
Argument(name="start_time", type="string", description="Start time for twitter API in YYYY-MM-DDTHH:mm:ssZ format")
99+
],
100+
executable=analyze_tweeted_images
101+
)
102+
]
103+
104+
worker = Worker(
105+
api_key=game_api_key,
106+
description="Processing incoming tweets. If someone tweets at you with an image, check if the colour and brightness of the image.",
107+
instruction="Get more information on tweeted images by running them through a image analyse to check colour and brightness",
108+
get_state_fn=get_state_fn,
109+
action_space=action_space
110+
)
111+
112+
# Get the worker to check if incoming tweets (in the last 15min) mentions contain fake images
113+
while True:
114+
worker.run("Analysing incoming tweets for the last 15 minutes")
115+
print("Waiting for 15 minutes...")
116+
time.sleep(15 * 60)

0 commit comments

Comments
 (0)