Skip to content

Commit 0544b86

Browse files
author
mossv2
committed
add plugin metadata and agent test
1 parent 978e799 commit 0544b86

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# General Information
2+
plugin_name: "membase" # Name of the plugin
3+
author: "felix from unibase" # Author and team name
4+
logo_url: "https://www.unibase.io/favicon.ico" # URL to the author photo or team logo (512x512 recommended)
5+
release_date: "14-04-2025" # Release date (DD-MM-YYYY)
6+
7+
# Description
8+
short_description: "Membase is a plugin for the Game SDK that allows you to store and retrieve memories from membase database." # One-liner description for listings
9+
detailed_description: "Membase is a plugin for the Game SDK that allows you to store and retrieve memories from membase database." # Full description with features and benefits
10+
11+
# Media & Assets
12+
plugin_logo_url: "https://www.unibase.io/favicon.ico" # URL to the plugin logo (512x512 recommended) (if any or fallback to logo_url)
13+
screenshots: # List of screenshots showcasing the plugin
14+
- "https://github.com/unibaseio/membase/blob/main/assets/virtual_case.png" # e.g., "https://example.com/screenshot1.png"
15+
- "https://github.com/unibaseio/membase/blob/main/assets/virtual_reload.png"
16+
demo_video_url: "" # Link to a demo or walkthrough video (if available)
17+
documentation_url: "https://www.unibase.io/" # Link to the plugin's official documentation (if available)
18+
changelog_url: "" # Link to the changelog (if maintained)
19+
20+
# Contact & Support
21+
x_account_handle: "" # X (formerly known as Twitter) account handle (ie: @GAME_Virtuals)
22+
support_contact: "" # Email or Slack/Discord link for user support
23+
community_link: "" # Forum or community link (if any)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import os
2+
from typing import Literal, Tuple
3+
from game_sdk.game.custom_types import Function, FunctionResultStatus, Argument
4+
from membase_plugin_gamesdk.membase_plugin_gamesdk import MembasePlugin
5+
from game_sdk.game.chat_agent import Chat, ChatAgent
6+
7+
8+
# set your own account and agent name
9+
# or set environment variables
10+
default_account = "game_sdk_test"
11+
default_agent_name = "game_sdk_test_agent"
12+
default_conversation_id = "67fd033a0740eed72502b65e"
13+
14+
game_api_key = os.environ.get("GAME_API_KEY")
15+
chat_agent = ChatAgent(
16+
prompt="You are a helpful assistant.",
17+
api_key=game_api_key,
18+
)
19+
20+
membase_plugin = MembasePlugin(
21+
account=default_account,
22+
agent_name=default_agent_name,
23+
auto_upload_to_hub=True,
24+
preload_from_hub=False,
25+
)
26+
27+
28+
def save_memory_executable(membase_plugin: MembasePlugin, memory: str, memory_type: Literal["user", "assistant"]) -> Tuple[FunctionResultStatus, str, dict]:
29+
try:
30+
membase_plugin.add_memory(memory, memory_type)
31+
return FunctionResultStatus.DONE, "Memory added successfully", {}
32+
except Exception as e:
33+
return FunctionResultStatus.FAILED, str(e), {}
34+
35+
def get_memory_executable(membase_plugin: MembasePlugin, recent_n: int = 10) -> Tuple[FunctionResultStatus, str, dict]:
36+
try:
37+
memory = membase_plugin.get_memory(recent_n=recent_n)
38+
result = ""
39+
for msg in memory:
40+
result += f"{msg.role}: {msg.content}\n"
41+
return FunctionResultStatus.DONE, result, {}
42+
except Exception as e:
43+
return FunctionResultStatus.FAILED, str(e), {}
44+
45+
action_space = [
46+
Function(
47+
fn_name="save_memory",
48+
fn_description="Save a memory to the membase database",
49+
args=[
50+
Argument(name="memory", type="str", description="The memory to save"),
51+
Argument(name="memory_type", type=["user", "assistant"], description="The type of memory to save"),
52+
],
53+
executable=lambda memory, memory_type: save_memory_executable(membase_plugin, memory, memory_type),
54+
),
55+
Function(
56+
fn_name="get_memory",
57+
fn_description="Get the last n memories from the membase database",
58+
args=[
59+
Argument(name="recent_n", type="int", description="The number of memories to retrieve"),
60+
],
61+
executable=lambda recent_n: get_memory_executable(membase_plugin, recent_n),
62+
)
63+
]
64+
65+
chat = chat_agent.create_chat(
66+
partner_id=default_account,
67+
partner_name=default_agent_name,
68+
action_space=action_space,
69+
)
70+
71+
membase_plugin.switch_conversation_id(default_conversation_id)
72+
membase_plugin.reload_memory(default_conversation_id)
73+
74+
chat_continue = True
75+
while chat_continue:
76+
77+
user_message = input("Enter a message: ")
78+
79+
response = chat.next(user_message)
80+
81+
if response.function_call:
82+
print(f"Function call: {response.function_call.fn_name}")
83+
84+
if response.message:
85+
print(f"Response: {response.message}")
86+
87+
if response.is_finished:
88+
chat_continue = False
89+
break
90+
91+
print("Chat ended")
92+

0 commit comments

Comments
 (0)