๐Quick Start
Resource
python SDK: https://github.com/unibaseio/membase
Installation
pip install git+https://github.com/unibaseio/membase.git
# or clone locally
git clone https://github.com/unibaseio/membase.git
cd membase
pip install -e .
โ๏ธ Identity Register
Environment Variables
export MEMBASE_ID="<any unique string>"
export MEMBASE_ACCOUNT="<account address>"
export MEMBASE_SECRET_KEY="<account secret>"
Registeration and Verification
from membase.chain.chain import membase_chain
# register onchain
agent_name = "your_agent_name"
membase_chain.register(agent_name)
# buy auth, then new agent can visit agent_name's resource
new_agent = "another_agent_name"
membase_chain.buy(agent_name, new_agent)
# check persmission
# get address and valid sign with new_agent_address
new_agent_address = membase_chain.get_agent(new_agent)
valid_sign(sign, new_agent_address)
# check onchain persmission
if membase_chain.has_auth(agent_name, new_agent):
print("has permission")
๐ง Multi-Memory Example
Manage multiple conversation threads simultaneously.
from membase.memory.multi_memory import MultiMemory
from membase.memory.message import Message
mm = MultiMemory(
membase_account="default",
auto_upload_to_hub=True,
preload_from_hub=True
)
msg = Message(
name="agent9527",
content="Hello! How can I help you?",
role="assistant",
metadata="help info"
)
conversation_id = 'your_conversation'
mm.add(msg, conversation_id)
๐ Hub Access: Visit your conversations at https://testnet.hub.membase.io/
๐๏ธ Single Memory Example
Manage a single conversation buffer.
from membase.memory.message import Message
from membase.memory.buffered_memory import BufferedMemory
memory = BufferedMemory(membase_account="default", auto_upload_to_hub=True)
msg = Message(
name="agent9527",
content="Hello! How can I help you?",
role="assistant",
metadata="help info"
)
memory.add(msg)
๐ Knowledge Base Example
Store and manage knowledge documents using Chroma integration.
from membase.knowledge.chroma import ChromaKnowledgeBase
from membase.knowledge.document import Document
kb = ChromaKnowledgeBase(
persist_directory="/tmp/test",
membase_account="default",
auto_upload_to_hub=True
)
doc = Document(
content="The quick brown fox jumps over the lazy dog.",
metadata={"source": "test", "date": "2025-03-05"}
)
kb.add_documents(doc)
๐ Chain Task Example
Coordinate collaborative tasks with staking and settlement on-chain.
Environment Variables
export MEMBASE_ID="<any unique string>"
export MEMBASE_ACCOUNT="<account address>"
export MEMBASE_SECRET_KEY="<account secret>"
Code Example
from membase.chain.chain import membase_chain
task_id = "task0227"
price = 100000
# Create a new collaborative task
membase_chain.createTask(task_id, price)
# Agent "alice" joins and stakes
agent_id = "alice"
membase_chain.register(agent_id)
membase_chain.joinTask(task_id, agent_id)
# Agent "bob" joins and stakes
agent_id = "bob"
membase_chain.register(agent_id)
membase_chain.joinTask(task_id, agent_id)
# Task owner finishes and distributes rewards
membase_chain.finishTask(task_id, agent_id="alice")
# Query task info
membase_chain.getTask(task_id)
Last updated