@mew-protocol/agent
v0.4.6
Published
TypeScript agent for MEW Protocol
Maintainers
Readme
MEW Protocol TypeScript Agent
A TypeScript implementation of a MEW Protocol agent that extends MEWParticipant from the SDK.
Features
- Extends
MEWParticipantclass for full protocol support - ReAct (Reasoning + Acting) loop implementation
- Transparent thinking/reasoning messages
- Built-in tool support (time, echo, calculator)
- MCP request/response handling
- Proposal fulfillment capabilities
- Configuration via YAML/JSON files
- Environment variable support
Installation
cd sdk/typescript-sdk/agent
npm install
npm run buildUsage
Basic Usage
# Run with defaults
npm start
# Or use the binary directly
node dist/index.jsCommand Line Options
node dist/index.js [options]
Options:
-g, --gateway <url> Gateway WebSocket URL (default: ws://localhost:8080)
-s, --space <name> Space name to join (default: playground)
-t, --token <token> Authentication token (default: agent-token)
-i, --id <id> Participant ID (default: typescript-agent)
-c, --config <file> Configuration file (YAML or JSON)
-d, --debug Enable debug logging
-h, --help Show help messageConfiguration File
Create a configuration file based on config.example.yaml:
participant_id: my-assistant
name: My Assistant
gateway: ws://localhost:8080
space: dev
token: my-token
systemPrompt: |
You are a helpful assistant that can...
thinkingEnabled: true
autoRespond: true
maxIterations: 5
logLevel: infoThen run:
node dist/index.js --config my-config.yamlEnvironment Variables
export MEW_GATEWAY=ws://localhost:8080
export MEW_SPACE=production
export MEW_TOKEN=secret-token
export MEW_PARTICIPANT_ID=prod-agent
npm startArchitecture
The agent is built on top of the MEW Protocol SDK:
import { MEWParticipant } from '@mew-protocol/participant';
export class MEWAgent extends MEWParticipant {
// Custom agent logic
}Key Components
- MEWAgent Class: Extends
MEWParticipantwith agent-specific behavior - ReAct Loop: Implements thinking and acting cycles
- Tool Registry: Manages available tools
- Message Handlers: Process different message types
- Reasoning Support: Transparent thinking messages
Message Flow
- Agent receives message (chat, MCP request, proposal)
- Starts reasoning sequence (if enabled)
- Runs ReAct loop to determine response
- Executes actions (tools, fulfillments)
- Sends response back
Development
Building
npm run build # Build once
npm run dev # Watch modeAdding Custom Tools
const customTool: Tool = {
name: 'my_tool',
description: 'Does something useful',
inputSchema: {
type: 'object',
properties: {
param: { type: 'string' }
}
},
handler: async (input) => {
// Tool implementation
return {
content: [{
type: 'text',
text: `Result: ${input.param}`
}]
};
}
};
agent.addTool(customTool);Extending the Agent
import { MEWAgent } from './MEWAgent';
class MyCustomAgent extends MEWAgent {
protected async think(input: string, previousThoughts: ThoughtStep[]): Promise<ThoughtStep> {
// Custom thinking logic
// Could integrate with LLMs here
}
protected async act(action: string, input: any): Promise<string> {
// Custom action execution
}
}Example Sessions
Basic Chat
User: Hello agent!
Agent: [thinking] Understanding greeting...
Agent: Hello! I am an AI assistant ready to help. What can I do for you?Tool Execution
User: What time is it?
Agent: [thinking] User wants to know the time...
Agent: [executes get_time tool]
Agent: The current time is 2025-09-11T10:30:00ZProposal Handling
Untrusted Agent: [proposes] Write to important.txt
TypeScript Agent: [evaluates safety]
TypeScript Agent: [fulfills if safe]Integration with LLMs
The agent is designed to integrate with LLMs. Override the think() method:
protected async think(input: string, previousThoughts: ThoughtStep[]): Promise<ThoughtStep> {
const response = await callLLM({
model: this.config.model,
messages: [
{ role: 'system', content: this.systemPrompt },
{ role: 'user', content: input }
]
});
return parseThought(response);
}License
MIT
