mashpy 0.2.2__tar.gz → 0.2.4__tar.gz
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.
- {mashpy-0.2.2 → mashpy-0.2.4}/PKG-INFO +1 -1
- {mashpy-0.2.2 → mashpy-0.2.4}/pyproject.toml +1 -1
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/logging/__init__.py +2 -1
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/logging/trace_context.py +12 -1
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/compaction.py +24 -16
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/runtime/runtime.py +33 -31
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mashpy.egg-info/PKG-INFO +1 -1
- {mashpy-0.2.2 → mashpy-0.2.4}/README.md +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/setup.cfg +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/agents/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/agents/masher/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/agents/masher/spec.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/agents/masher/tool.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/api/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/api/app.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/api/config.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/api/main.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/api/static/telemetry/assets/index-BO7oh6gk.css +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/api/static/telemetry/assets/index-CGIrz-UH.js +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/api/static/telemetry/index.html +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/api/telemetry_ui.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/api/types.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/cli/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/cli/chain_renderer.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/cli/client.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/cli/commands.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/cli/config.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/cli/default_commands.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/cli/main.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/cli/render.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/cli/repl.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/cli/shell.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/cli/types.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/core/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/core/agent.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/core/config.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/core/context.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/core/llm/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/core/llm/anthropic.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/core/llm/base.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/core/llm/openai.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/core/llm/types.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/core/llm/utils.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/logging/events.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/logging/logger.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/mcp/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/mcp/client.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/mcp/host.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/mcp/manager.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/mcp/server.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/mcp/types.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/search/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/search/parser.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/search/rerank.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/search/retrieval.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/search/service.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/search/types.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/signals.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/store/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/store/backends/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/store/backends/sqlite/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/store/backends/sqlite/store.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/memory/store/protocol.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/runtime/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/runtime/client.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/runtime/errors.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/runtime/host.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/runtime/server.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/runtime/session.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/runtime/spec.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/runtime/types.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/skills/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/skills/base.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/skills/registry.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/skills/tool.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/testing/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/testing/runtime_fixtures.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/tools/__init__.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/tools/base.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/tools/bash.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/tools/mcp.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/tools/registry.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/tools/runtime.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mash/tools/subagent.py +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mashpy.egg-info/SOURCES.txt +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mashpy.egg-info/dependency_links.txt +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mashpy.egg-info/entry_points.txt +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mashpy.egg-info/requires.txt +0 -0
- {mashpy-0.2.2 → mashpy-0.2.4}/src/mashpy.egg-info/top_level.txt +0 -0
|
@@ -10,7 +10,7 @@ from .events import (
|
|
|
10
10
|
MCPEvent,
|
|
11
11
|
)
|
|
12
12
|
from .logger import EventLogger
|
|
13
|
-
from .trace_context import clear_trace_id, get_trace_id, set_trace_id
|
|
13
|
+
from .trace_context import bound_trace_id, clear_trace_id, get_trace_id, set_trace_id
|
|
14
14
|
|
|
15
15
|
__all__ = [
|
|
16
16
|
"LogEvent",
|
|
@@ -21,6 +21,7 @@ __all__ = [
|
|
|
21
21
|
"MemorySearchEvent",
|
|
22
22
|
"DebugEvent",
|
|
23
23
|
"EventLogger",
|
|
24
|
+
"bound_trace_id",
|
|
24
25
|
"set_trace_id",
|
|
25
26
|
"get_trace_id",
|
|
26
27
|
"clear_trace_id",
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import contextvars
|
|
6
|
-
from
|
|
6
|
+
from contextlib import contextmanager
|
|
7
|
+
from typing import Iterator, Optional
|
|
7
8
|
|
|
8
9
|
_trace_id: contextvars.ContextVar[str | None] = contextvars.ContextVar(
|
|
9
10
|
"mash_trace_id",
|
|
@@ -24,3 +25,13 @@ def get_trace_id() -> Optional[str]:
|
|
|
24
25
|
def clear_trace_id() -> None:
|
|
25
26
|
"""Clear the trace ID for the current task context."""
|
|
26
27
|
_trace_id.set(None)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@contextmanager
|
|
31
|
+
def bound_trace_id(trace_id: Optional[str]) -> Iterator[None]:
|
|
32
|
+
"""Temporarily bind a trace ID for the current task context."""
|
|
33
|
+
token = _trace_id.set(trace_id)
|
|
34
|
+
try:
|
|
35
|
+
yield
|
|
36
|
+
finally:
|
|
37
|
+
_trace_id.reset(token)
|
|
@@ -7,6 +7,7 @@ from typing import Any, Dict, List, Tuple
|
|
|
7
7
|
|
|
8
8
|
from ..core.llm import LLMProvider
|
|
9
9
|
from ..core.llm.types import LLMContentBlock, LLMMessage, LLMRequest
|
|
10
|
+
from ..logging import bound_trace_id
|
|
10
11
|
from .store import MemoryStore
|
|
11
12
|
|
|
12
13
|
COMPACTION_SYSTEM_PROMPT = """You are a conversation compactor.
|
|
@@ -75,23 +76,31 @@ async def compact_conversation(
|
|
|
75
76
|
if not lines:
|
|
76
77
|
return "", ""
|
|
77
78
|
|
|
79
|
+
trace_id = str(uuid.uuid4())
|
|
78
80
|
conversation_text = "\n".join(lines)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
if hasattr(llm, "set_trace_id"):
|
|
82
|
+
llm.set_trace_id(trace_id)
|
|
83
|
+
try:
|
|
84
|
+
with bound_trace_id(trace_id):
|
|
85
|
+
response = await llm.send(
|
|
86
|
+
LLMRequest(
|
|
87
|
+
model=llm.model,
|
|
88
|
+
system=COMPACTION_SYSTEM_PROMPT,
|
|
89
|
+
messages=[
|
|
90
|
+
LLMMessage(
|
|
91
|
+
role="user",
|
|
92
|
+
content=[LLMContentBlock.text(conversation_text)],
|
|
93
|
+
)
|
|
94
|
+
],
|
|
95
|
+
tools=[],
|
|
96
|
+
max_tokens=max_tokens,
|
|
97
|
+
temperature=temperature,
|
|
98
|
+
use_prompt_caching=False,
|
|
87
99
|
)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
use_prompt_caching=False,
|
|
93
|
-
)
|
|
94
|
-
)
|
|
100
|
+
)
|
|
101
|
+
finally:
|
|
102
|
+
if hasattr(llm, "set_trace_id"):
|
|
103
|
+
llm.set_trace_id(None)
|
|
95
104
|
summary_text = response.text.strip()
|
|
96
105
|
|
|
97
106
|
metadata: Dict[str, Any] = {
|
|
@@ -102,7 +111,6 @@ async def compact_conversation(
|
|
|
102
111
|
"app_id": app_id,
|
|
103
112
|
"token_usage": {"input": 0, "output": 0},
|
|
104
113
|
}
|
|
105
|
-
trace_id = str(uuid.uuid4())
|
|
106
114
|
turn_id = await store.save_turn(
|
|
107
115
|
trace_id=trace_id,
|
|
108
116
|
session_id=session_id,
|
|
@@ -223,38 +223,40 @@ class MashAgentRuntime:
|
|
|
223
223
|
manager = self.mcp_manager
|
|
224
224
|
try:
|
|
225
225
|
for server in mcp_servers:
|
|
226
|
-
manager.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
mcp_tools = manager.get_flattened_tools(prefix="mcp_")
|
|
235
|
-
for mcp_tool in mcp_tools:
|
|
236
|
-
server_name = mcp_tool.get("metadata", {}).get("server")
|
|
237
|
-
original_name = mcp_tool.get("metadata", {}).get("original_name")
|
|
238
|
-
if not server_name or not original_name:
|
|
239
|
-
continue
|
|
240
|
-
|
|
241
|
-
def make_executor(srv_name: str, tool_name: str):
|
|
242
|
-
def executor(args):
|
|
243
|
-
try:
|
|
244
|
-
result = manager.call_tool(srv_name, tool_name, args)
|
|
245
|
-
return extract_mcp_text(result)
|
|
246
|
-
except Exception as exc: # pragma: no cover
|
|
247
|
-
return f"Error: {exc}"
|
|
248
|
-
|
|
249
|
-
return executor
|
|
250
|
-
|
|
251
|
-
adapter = MCPToolAdapter.from_mcp_tool(
|
|
252
|
-
mcp_tool=mcp_tool,
|
|
253
|
-
executor=make_executor(server_name, original_name),
|
|
254
|
-
prefix="",
|
|
226
|
+
if manager.get_server(server.name) is None:
|
|
227
|
+
manager.add_server(
|
|
228
|
+
name=server.name,
|
|
229
|
+
url=server.url,
|
|
230
|
+
description=server.description,
|
|
231
|
+
headers=server.headers,
|
|
232
|
+
allowed_tools=server.allowed_tools,
|
|
233
|
+
auto_connect=True,
|
|
255
234
|
)
|
|
256
|
-
|
|
257
|
-
|
|
235
|
+
|
|
236
|
+
mcp_tools = manager.get_flattened_tools(prefix="mcp_")
|
|
237
|
+
for mcp_tool in mcp_tools:
|
|
238
|
+
server_name = mcp_tool.get("metadata", {}).get("server")
|
|
239
|
+
original_name = mcp_tool.get("metadata", {}).get("original_name")
|
|
240
|
+
if not server_name or not original_name:
|
|
241
|
+
continue
|
|
242
|
+
|
|
243
|
+
def make_executor(srv_name: str, tool_name: str):
|
|
244
|
+
def executor(args):
|
|
245
|
+
try:
|
|
246
|
+
result = manager.call_tool(srv_name, tool_name, args)
|
|
247
|
+
return extract_mcp_text(result)
|
|
248
|
+
except Exception as exc: # pragma: no cover
|
|
249
|
+
return f"Error: {exc}"
|
|
250
|
+
|
|
251
|
+
return executor
|
|
252
|
+
|
|
253
|
+
adapter = MCPToolAdapter.from_mcp_tool(
|
|
254
|
+
mcp_tool=mcp_tool,
|
|
255
|
+
executor=make_executor(server_name, original_name),
|
|
256
|
+
prefix="",
|
|
257
|
+
)
|
|
258
|
+
if adapter.name not in agent.tools:
|
|
259
|
+
agent.tools.register(adapter)
|
|
258
260
|
except MCPClientError:
|
|
259
261
|
return
|
|
260
262
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|