agentlaunch-templates 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +21 -9
- package/dist/generator.js.map +1 -1
- package/dist/templates/chat-memory.d.ts +5 -1
- package/dist/templates/chat-memory.d.ts.map +1 -1
- package/dist/templates/chat-memory.js +159 -71
- package/dist/templates/chat-memory.js.map +1 -1
- package/package.json +1 -1
package/dist/generator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsBH,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,cAAc,EAAE,MAAM,CAAC;IACvB,qDAAqD;IACrD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsBH,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,cAAc,EAAE,MAAM,CAAC;IACvB,qDAAqD;IACrD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAilBD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA+BhE;AAMD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACrB,GAAG,MAAM,CAsBT;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,OAAO,GAAE,eAAmC,GAC3C,cAAc,CAqBhB"}
|
package/dist/generator.js
CHANGED
|
@@ -83,6 +83,11 @@ function buildReadme(template, vars) {
|
|
|
83
83
|
|
|
84
84
|
${description}
|
|
85
85
|
|
|
86
|
+
**Built-in features:**
|
|
87
|
+
- Persistent conversation memory (survives restarts)
|
|
88
|
+
- ASI1-mini LLM with domain-specific system prompt
|
|
89
|
+
- Chat Protocol v0.3.0 (discoverable on Agentverse + ASI:One)
|
|
90
|
+
|
|
86
91
|
Generated by \`npx agentlaunch\` using the **${template.name}** template.
|
|
87
92
|
|
|
88
93
|
## Quickstart
|
|
@@ -189,7 +194,7 @@ function buildEnvExample(template, vars) {
|
|
|
189
194
|
const extraSecrets = template.secrets.filter((s) => !baseSecrets.has(s));
|
|
190
195
|
if (extraSecrets.length > 0) {
|
|
191
196
|
lines.push(``);
|
|
192
|
-
lines.push(`#
|
|
197
|
+
lines.push(`# Agent secrets (auto-set during deploy, override here for local dev)`);
|
|
193
198
|
for (const secret of extraSecrets) {
|
|
194
199
|
lines.push(`${secret}=`);
|
|
195
200
|
}
|
|
@@ -562,15 +567,22 @@ export function generateSystemPrompt(description) {
|
|
|
562
567
|
return template.replace(/\{\{description\}\}/g, trimmed.toLowerCase());
|
|
563
568
|
}
|
|
564
569
|
}
|
|
565
|
-
// Fallback:
|
|
566
|
-
// Handle descriptions that start with verbs (e.g. "answers questions about X")
|
|
570
|
+
// Fallback: build a rich prompt from the description
|
|
567
571
|
const lower = trimmed.toLowerCase();
|
|
568
572
|
const startsWithVerb = /^(answers?|helps?|provides?|monitors?|tracks?|analyz|finds?|generates?|creates?|manages?|handles?)/.test(lower);
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
573
|
+
const core = startsWithVerb
|
|
574
|
+
? `You are an AI agent that ${lower}.`
|
|
575
|
+
: `You are an AI agent specializing in: ${trimmed}.`;
|
|
576
|
+
return `${core}
|
|
577
|
+
|
|
578
|
+
Your role is to be genuinely useful — give specific, actionable answers rather than generic advice. When users ask questions, draw on deep knowledge of this domain to provide the kind of expert guidance they'd get from a specialist.
|
|
579
|
+
|
|
580
|
+
Guidelines:
|
|
581
|
+
- Be concise but thorough. Short answers for simple questions, detailed answers for complex ones.
|
|
582
|
+
- Use examples and concrete specifics rather than abstract explanations.
|
|
583
|
+
- If you don't know something, say so rather than guessing.
|
|
584
|
+
- Remember the conversation context — refer back to what the user has already told you.
|
|
585
|
+
- Proactively suggest next steps or related things the user might want to know.`;
|
|
574
586
|
}
|
|
575
587
|
// ---------------------------------------------------------------------------
|
|
576
588
|
// Welcome message generation for Claude Code sessions
|
|
@@ -587,7 +599,7 @@ export function generateWelcomeMessage(opts) {
|
|
|
587
599
|
Description: ${description}
|
|
588
600
|
|
|
589
601
|
The agent is live with:
|
|
590
|
-
-
|
|
602
|
+
- Persistent conversation memory (last 20 messages per user, persistent across restarts)
|
|
591
603
|
- LLM integration (ASI1-mini)
|
|
592
604
|
- Chat Protocol v0.3.0 (discoverable on Agentverse)
|
|
593
605
|
- Custom system prompt matching its purpose
|
package/dist/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAA6C,MAAM,eAAe,CAAC;AAEvF,8EAA8E;AAC9E,mCAAmC;AACnC,8EAA8E;AAE9E,MAAM,YAAY,GAAG,6BAA6B,CAAC;AACnD,MAAM,WAAW,GAAG,iEAAiE,CAAC;AACtF,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB;IACvD,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;AAExE,MAAM,iBAAiB,GAAG,yBAAyB,CAAC;AACpD,MAAM,gBAAgB,GAAG,kEAAkE,CAAC;AAC5F,MAAM,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB;IACjE,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,KAAK,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;AAiClF,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E;;;GAGG;AACH,SAAS,UAAU,CAAC,IAAY,EAAE,IAA4B;IAC5D,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,GAAW,EAAE,EAAE;QAC3D,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI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AG,UAAU,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACnD,MAAM,cAAc,GAAG,mBAAmB,EAAE,CAAC;IAC7C,MAAM,iBAAiB,GAAG,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACrE,MAAM,gBAAgB,GAAG,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;AACrG,CAAC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* chat-memory.ts — Base template with
|
|
2
|
+
* chat-memory.ts — Base template with persistent memory, LLM, and chat protocol
|
|
3
|
+
*
|
|
4
|
+
* This is the default template for all agents created with `npx agentlaunch`.
|
|
5
|
+
* It provides a solid foundation: conversation memory that survives restarts,
|
|
6
|
+
* ASI1-mini LLM for intelligent responses, and domain-specific system prompts.
|
|
3
7
|
*
|
|
4
8
|
* Platform constants (source of truth: deployed smart contracts):
|
|
5
9
|
* - Deploy fee: 120 FET (read dynamically, can change via multi-sig)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-memory.d.ts","sourceRoot":"","sources":["../../src/templates/chat-memory.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"chat-memory.d.ts","sourceRoot":"","sources":["../../src/templates/chat-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQpD,eAAO,MAAM,QAAQ,EAAE,aA0RtB,CAAC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* chat-memory.ts — Base template with
|
|
2
|
+
* chat-memory.ts — Base template with persistent memory, LLM, and chat protocol
|
|
3
|
+
*
|
|
4
|
+
* This is the default template for all agents created with `npx agentlaunch`.
|
|
5
|
+
* It provides a solid foundation: conversation memory that survives restarts,
|
|
6
|
+
* ASI1-mini LLM for intelligent responses, and domain-specific system prompts.
|
|
3
7
|
*
|
|
4
8
|
* Platform constants (source of truth: deployed smart contracts):
|
|
5
9
|
* - Deploy fee: 120 FET (read dynamically, can change via multi-sig)
|
|
@@ -13,7 +17,7 @@ const RESOLVED_API_URL = process.env.AGENT_LAUNCH_API_URL ??
|
|
|
13
17
|
(process.env.AGENT_LAUNCH_ENV === 'dev' ? DEV_API_URL : PROD_API_URL);
|
|
14
18
|
export const template = {
|
|
15
19
|
name: "chat-memory",
|
|
16
|
-
description: "Chat agent with
|
|
20
|
+
description: "Chat agent with persistent memory and LLM — recommended starting point",
|
|
17
21
|
category: "General",
|
|
18
22
|
variables: [
|
|
19
23
|
{ name: "agent_name", required: true, description: "Name of the agent" },
|
|
@@ -22,19 +26,29 @@ export const template = {
|
|
|
22
26
|
required: true,
|
|
23
27
|
description: "Short description of what this agent does",
|
|
24
28
|
},
|
|
29
|
+
{
|
|
30
|
+
name: "system_prompt",
|
|
31
|
+
default: "You are a helpful AI assistant. Be concise and accurate.",
|
|
32
|
+
description: "System prompt for the LLM (auto-generated from description)",
|
|
33
|
+
},
|
|
25
34
|
{
|
|
26
35
|
name: "memory_size",
|
|
27
|
-
default: "
|
|
36
|
+
default: "20",
|
|
28
37
|
description: "Number of messages to remember per user",
|
|
29
38
|
},
|
|
30
39
|
],
|
|
31
|
-
dependencies: ["requests"],
|
|
32
|
-
secrets: ["AGENTVERSE_API_KEY", "AGENTLAUNCH_API_KEY", "AGENT_ADDRESS"],
|
|
40
|
+
dependencies: ["requests", "openai"],
|
|
41
|
+
secrets: ["AGENTVERSE_API_KEY", "AGENTLAUNCH_API_KEY", "AGENT_ADDRESS", "ASI1_API_KEY"],
|
|
33
42
|
code: `#!/usr/bin/env python3
|
|
34
43
|
"""
|
|
35
|
-
{{agent_name}} — AgentLaunch
|
|
44
|
+
{{agent_name}} — AgentLaunch Agent
|
|
36
45
|
Generated by: agentlaunch scaffold {{agent_name}} --type chat-memory
|
|
37
46
|
|
|
47
|
+
Features:
|
|
48
|
+
- Persistent conversation memory (survives agent restarts)
|
|
49
|
+
- ASI1-mini LLM with domain-specific system prompt
|
|
50
|
+
- Chat Protocol v0.3.0 (discoverable on Agentverse + ASI:One)
|
|
51
|
+
|
|
38
52
|
Platform constants (source of truth: deployed smart contracts):
|
|
39
53
|
- Deploy fee: 120 FET (read dynamically, can change via multi-sig)
|
|
40
54
|
- Graduation target: 30,000 FET -> auto DEX listing
|
|
@@ -47,23 +61,20 @@ from uagents_core.contrib.protocols.chat import (
|
|
|
47
61
|
ChatMessage,
|
|
48
62
|
EndSessionContent,
|
|
49
63
|
TextContent,
|
|
64
|
+
chat_protocol_spec,
|
|
50
65
|
)
|
|
51
|
-
try:
|
|
52
|
-
from uagents_core.contrib.protocols.chat import create_protocol as _create_chat
|
|
53
|
-
except ImportError:
|
|
54
|
-
_create_chat = None
|
|
55
|
-
try:
|
|
56
|
-
from uagents_core.contrib.protocols.chat import chat_protocol_spec as _chat_spec
|
|
57
|
-
except ImportError:
|
|
58
|
-
_chat_spec = None
|
|
59
|
-
|
|
60
66
|
import json
|
|
61
67
|
import os
|
|
62
68
|
from collections import defaultdict
|
|
63
69
|
from datetime import datetime
|
|
64
|
-
from typing import Dict, List
|
|
70
|
+
from typing import Dict, List, Optional
|
|
65
71
|
from uuid import uuid4
|
|
66
72
|
|
|
73
|
+
try:
|
|
74
|
+
from openai import OpenAI
|
|
75
|
+
except ImportError:
|
|
76
|
+
OpenAI = None
|
|
77
|
+
|
|
67
78
|
# ==============================================================================
|
|
68
79
|
# CONFIG
|
|
69
80
|
# ==============================================================================
|
|
@@ -71,57 +82,141 @@ from uuid import uuid4
|
|
|
71
82
|
AGENTLAUNCH_API = os.environ.get("AGENTLAUNCH_API", "${RESOLVED_API_URL}")
|
|
72
83
|
MEMORY_SIZE = {{memory_size}}
|
|
73
84
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
85
|
+
AGENT_NAME = "{{agent_name}}"
|
|
86
|
+
AGENT_DESCRIPTION = "{{description}}"
|
|
87
|
+
AGENT_VERSION = "1.0.0"
|
|
88
|
+
|
|
89
|
+
SYSTEM_PROMPT = """{{system_prompt}}"""
|
|
79
90
|
|
|
80
91
|
# ==============================================================================
|
|
81
|
-
# CONVERSATION MEMORY
|
|
92
|
+
# PERSISTENT CONVERSATION MEMORY
|
|
82
93
|
# ==============================================================================
|
|
83
94
|
|
|
84
95
|
class ConversationMemory:
|
|
85
|
-
"""
|
|
96
|
+
"""Per-user conversation history with ctx.storage persistence.
|
|
97
|
+
|
|
98
|
+
Memory is stored per-user in ctx.storage so it survives agent restarts.
|
|
99
|
+
Each user's history is stored under key 'mem_{user_id_hash}' to avoid
|
|
100
|
+
key collisions and keep storage organized.
|
|
101
|
+
"""
|
|
86
102
|
|
|
87
103
|
def __init__(self, max_messages: int = MEMORY_SIZE) -> None:
|
|
88
|
-
self._history: Dict[str, List[Dict]] = defaultdict(list)
|
|
89
104
|
self._max = max_messages
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
105
|
+
self._cache: Dict[str, List[Dict[str, str]]] = {}
|
|
106
|
+
|
|
107
|
+
def _key(self, user_id: str) -> str:
|
|
108
|
+
"""Storage key for a user's conversation history."""
|
|
109
|
+
short_id = user_id[-12:] # Last 12 chars of address for readability
|
|
110
|
+
return f"mem_{short_id}"
|
|
111
|
+
|
|
112
|
+
def load(self, ctx: Context, user_id: str) -> None:
|
|
113
|
+
"""Load a user's history from persistent storage into cache."""
|
|
114
|
+
if user_id in self._cache:
|
|
115
|
+
return # Already loaded
|
|
116
|
+
raw = ctx.storage.get(self._key(user_id))
|
|
117
|
+
if raw:
|
|
118
|
+
try:
|
|
119
|
+
self._cache[user_id] = json.loads(raw)[-self._max:]
|
|
120
|
+
except (json.JSONDecodeError, TypeError):
|
|
121
|
+
self._cache[user_id] = []
|
|
122
|
+
else:
|
|
123
|
+
self._cache[user_id] = []
|
|
124
|
+
|
|
125
|
+
def save(self, ctx: Context, user_id: str) -> None:
|
|
126
|
+
"""Persist a user's history to ctx.storage."""
|
|
127
|
+
history = self._cache.get(user_id, [])
|
|
128
|
+
ctx.storage.set(self._key(user_id), json.dumps(history))
|
|
129
|
+
|
|
130
|
+
def add(self, ctx: Context, user_id: str, role: str, content: str) -> None:
|
|
131
|
+
"""Add a message and persist."""
|
|
132
|
+
self.load(ctx, user_id)
|
|
133
|
+
self._cache[user_id].append({
|
|
93
134
|
"role": role,
|
|
94
135
|
"content": content,
|
|
95
|
-
"
|
|
136
|
+
"ts": datetime.now().isoformat(),
|
|
96
137
|
})
|
|
97
|
-
if len(self.
|
|
98
|
-
self.
|
|
138
|
+
if len(self._cache[user_id]) > self._max:
|
|
139
|
+
self._cache[user_id] = self._cache[user_id][-self._max:]
|
|
140
|
+
self.save(ctx, user_id)
|
|
141
|
+
|
|
142
|
+
def get(self, ctx: Context, user_id: str) -> List[Dict[str, str]]:
|
|
143
|
+
"""Get conversation history for a user."""
|
|
144
|
+
self.load(ctx, user_id)
|
|
145
|
+
return list(self._cache.get(user_id, []))
|
|
146
|
+
|
|
147
|
+
def clear(self, ctx: Context, user_id: str) -> None:
|
|
148
|
+
"""Clear a user's history from cache and storage."""
|
|
149
|
+
self._cache[user_id] = []
|
|
150
|
+
self.save(ctx, user_id)
|
|
151
|
+
|
|
152
|
+
def summary(self, ctx: Context, user_id: str, n: int = 5) -> str:
|
|
153
|
+
"""Human-readable summary of recent messages."""
|
|
154
|
+
history = self.get(ctx, user_id)
|
|
155
|
+
if not history:
|
|
156
|
+
return "No conversation history."
|
|
157
|
+
lines = []
|
|
158
|
+
for m in history[-n:]:
|
|
159
|
+
role = m["role"].upper()
|
|
160
|
+
text = m["content"][:120]
|
|
161
|
+
lines.append(f" [{role}] {text}")
|
|
162
|
+
return f"Last {min(n, len(history))} of {len(history)} messages:\\n" + "\\n".join(lines)
|
|
99
163
|
|
|
100
|
-
|
|
101
|
-
|
|
164
|
+
# ==============================================================================
|
|
165
|
+
# LLM (ASI1-mini via OpenAI-compatible API)
|
|
166
|
+
# ==============================================================================
|
|
102
167
|
|
|
103
|
-
|
|
104
|
-
|
|
168
|
+
_llm_client = None
|
|
169
|
+
|
|
170
|
+
def get_llm_client() -> Optional["OpenAI"]:
|
|
171
|
+
"""Get or create OpenAI client configured for ASI1-mini."""
|
|
172
|
+
global _llm_client
|
|
173
|
+
if _llm_client is not None:
|
|
174
|
+
return _llm_client
|
|
175
|
+
api_key = os.environ.get("ASI1_API_KEY", "")
|
|
176
|
+
if not api_key or OpenAI is None:
|
|
177
|
+
return None
|
|
178
|
+
_llm_client = OpenAI(base_url="https://api.asi1.ai/v1", api_key=api_key)
|
|
179
|
+
return _llm_client
|
|
180
|
+
|
|
181
|
+
def llm_respond(user_text: str, history: List[Dict[str, str]]) -> str:
|
|
182
|
+
"""Generate a response using ASI1-mini with conversation history."""
|
|
183
|
+
client = get_llm_client()
|
|
184
|
+
if client is None:
|
|
185
|
+
return (
|
|
186
|
+
"I received your message but LLM is not configured yet. "
|
|
187
|
+
"Please set the ASI1_API_KEY secret on Agentverse."
|
|
188
|
+
)
|
|
105
189
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
190
|
+
# Build messages: system prompt + conversation history + current message
|
|
191
|
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
|
192
|
+
for m in history:
|
|
193
|
+
messages.append({"role": m["role"], "content": m["content"]})
|
|
194
|
+
messages.append({"role": "user", "content": user_text})
|
|
195
|
+
|
|
196
|
+
try:
|
|
197
|
+
resp = client.chat.completions.create(
|
|
198
|
+
model="asi1-mini",
|
|
199
|
+
messages=messages,
|
|
200
|
+
max_tokens=1024,
|
|
201
|
+
temperature=0.7,
|
|
202
|
+
)
|
|
203
|
+
return resp.choices[0].message.content.strip()
|
|
204
|
+
except Exception as e:
|
|
205
|
+
return f"Sorry, I encountered an error generating a response: {e}"
|
|
112
206
|
|
|
113
207
|
# ==============================================================================
|
|
114
208
|
# REPLY HELPER
|
|
115
209
|
# ==============================================================================
|
|
116
210
|
|
|
117
211
|
async def reply(ctx: Context, sender: str, text: str, end: bool = False) -> None:
|
|
212
|
+
"""Send a chat message, optionally ending the session."""
|
|
118
213
|
content = [TextContent(type="text", text=text)]
|
|
119
214
|
if end:
|
|
120
215
|
content.append(EndSessionContent(type="end-session"))
|
|
121
216
|
try:
|
|
122
217
|
await ctx.send(
|
|
123
218
|
sender,
|
|
124
|
-
ChatMessage(timestamp=datetime.
|
|
219
|
+
ChatMessage(timestamp=datetime.now(), msg_id=uuid4(), content=content),
|
|
125
220
|
)
|
|
126
221
|
except Exception as e:
|
|
127
222
|
ctx.logger.error(f"Failed to send reply: {e}")
|
|
@@ -132,71 +227,64 @@ async def reply(ctx: Context, sender: str, text: str, end: bool = False) -> None
|
|
|
132
227
|
|
|
133
228
|
memory = ConversationMemory(max_messages=MEMORY_SIZE)
|
|
134
229
|
agent = Agent()
|
|
135
|
-
chat_proto =
|
|
230
|
+
chat_proto = Protocol(spec=chat_protocol_spec)
|
|
136
231
|
|
|
137
232
|
@chat_proto.on_message(ChatMessage)
|
|
138
233
|
async def handle_chat(ctx: Context, sender: str, msg: ChatMessage) -> None:
|
|
139
|
-
#
|
|
234
|
+
# Acknowledge receipt
|
|
140
235
|
try:
|
|
141
236
|
await ctx.send(
|
|
142
237
|
sender,
|
|
143
|
-
ChatAcknowledgement(
|
|
144
|
-
timestamp=datetime.utcnow(), acknowledged_msg_id=msg.msg_id
|
|
145
|
-
),
|
|
238
|
+
ChatAcknowledgement(timestamp=datetime.now(), acknowledged_msg_id=msg.msg_id),
|
|
146
239
|
)
|
|
147
240
|
except Exception as e:
|
|
148
241
|
ctx.logger.error(f"Failed to send ack: {e}")
|
|
149
242
|
|
|
150
|
-
# Extract text
|
|
243
|
+
# Extract text
|
|
151
244
|
text = " ".join(
|
|
152
245
|
item.text for item in msg.content if isinstance(item, TextContent)
|
|
153
246
|
).strip()[:2000]
|
|
154
247
|
|
|
155
248
|
if not text:
|
|
156
|
-
await reply(ctx, sender, "Please send a message.", end=True)
|
|
249
|
+
await reply(ctx, sender, "Please send a text message.", end=True)
|
|
157
250
|
return
|
|
158
251
|
|
|
159
|
-
lower = text.lower()
|
|
252
|
+
lower = text.lower().strip()
|
|
253
|
+
|
|
254
|
+
# --- Built-in commands ---
|
|
160
255
|
|
|
161
|
-
# Help command
|
|
162
256
|
if lower in ("help", "?"):
|
|
163
257
|
await reply(
|
|
164
|
-
ctx,
|
|
165
|
-
|
|
166
|
-
f"
|
|
167
|
-
f"{BUSINESS['description']}\\n\\n"
|
|
258
|
+
ctx, sender,
|
|
259
|
+
f"**{AGENT_NAME}** v{AGENT_VERSION}\\n\\n"
|
|
260
|
+
f"{AGENT_DESCRIPTION}\\n\\n"
|
|
168
261
|
f"Commands: help, history, clear",
|
|
169
262
|
)
|
|
170
263
|
return
|
|
171
264
|
|
|
172
|
-
# History command
|
|
173
265
|
if lower == "history":
|
|
174
|
-
summary = memory.summary(sender)
|
|
175
|
-
await reply(ctx, sender, f"**
|
|
266
|
+
summary = memory.summary(ctx, sender)
|
|
267
|
+
await reply(ctx, sender, f"**Conversation History**\\n{summary}")
|
|
176
268
|
return
|
|
177
269
|
|
|
178
|
-
# Clear command
|
|
179
270
|
if lower == "clear":
|
|
180
|
-
memory.clear(sender)
|
|
271
|
+
memory.clear(ctx, sender)
|
|
181
272
|
await reply(ctx, sender, "Conversation history cleared.", end=True)
|
|
182
273
|
return
|
|
183
274
|
|
|
184
|
-
#
|
|
185
|
-
|
|
275
|
+
# --- LLM response with conversation memory ---
|
|
276
|
+
|
|
277
|
+
# Get prior history for context (before adding current message)
|
|
278
|
+
history = memory.get(ctx, sender)
|
|
186
279
|
|
|
187
|
-
#
|
|
188
|
-
|
|
189
|
-
context_msgs = len(history) - 1 # Exclude current message
|
|
280
|
+
# Store user message
|
|
281
|
+
memory.add(ctx, sender, "user", text)
|
|
190
282
|
|
|
191
|
-
# Generate response
|
|
192
|
-
response = (
|
|
193
|
-
f"I received your message: '{text[:100]}'\\n\\n"
|
|
194
|
-
f"I have {context_msgs} previous messages in memory.\\n\\n"
|
|
195
|
-
f"This is a template — customize the response logic in handle_chat()."
|
|
196
|
-
)
|
|
283
|
+
# Generate response
|
|
284
|
+
response = llm_respond(text, history)
|
|
197
285
|
|
|
198
286
|
# Store assistant response
|
|
199
|
-
memory.add(sender, "assistant", response[:
|
|
287
|
+
memory.add(ctx, sender, "assistant", response[:2000])
|
|
200
288
|
|
|
201
289
|
await reply(ctx, sender, response, end=True)
|
|
202
290
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-memory.js","sourceRoot":"","sources":["../../src/templates/chat-memory.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"chat-memory.js","sourceRoot":"","sources":["../../src/templates/chat-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,6FAA6F;AAC7F,MAAM,YAAY,GAAG,6BAA6B,CAAC;AACnD,MAAM,WAAW,GAAG,iEAAiE,CAAC;AACtF,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB;IACvD,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,QAAQ,GAAkB;IACrC,IAAI,EAAE,aAAa;IACnB,W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