personal memory agent
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Clean up dead code in agent backends, validate Gemini responses

- Add empty response check in google.py - raises error if model returns
null/empty text instead of emitting finish with result: null
- Move setup_logging() to agents.py instead of importing from backend
- Remove unused functions: setup_logging (all backends), run_prompt (all),
call_filtered_tool (google)
- Fix stale docstrings referencing non-existent AgentSession class
- Remove unused sys import from openai.py

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

+15 -86
+11 -4
muse/agents.py
··· 3 3 import argparse 4 4 import asyncio 5 5 import json 6 + import logging 6 7 import os 7 8 import sys 8 9 import time ··· 11 12 from typing import Any, Callable, Literal, Optional, TypedDict, Union 12 13 13 14 from think.utils import setup_cli 15 + 16 + LOG = logging.getLogger("muse.agents") 17 + 18 + 19 + def setup_logging(verbose: bool = False) -> logging.Logger: 20 + """Configure logging for agent CLI.""" 21 + level = logging.DEBUG if verbose else logging.INFO 22 + logging.basicConfig(level=level, stream=sys.stdout) 23 + return LOG 14 24 15 25 16 26 class ToolStartEvent(TypedDict, total=False): ··· 267 277 268 278 args = setup_cli(parser) 269 279 270 - # Import openai for logging setup 271 - from . import openai as openai_mod 272 - 273 - app_logger = openai_mod.setup_logging(args.verbose) 280 + app_logger = setup_logging(args.verbose) 274 281 275 282 # Always write to stdout only 276 283 event_writer = JSONEventWriter(None)
+1 -25
muse/anthropic.py
··· 1 1 #!/usr/bin/env python3 2 2 """Anthropic Claude backed agent implementation. 3 3 4 - This module exposes :class:`AgentSession` for interacting with Anthropic's 5 - Claude API and is used by the ``muse-agents`` CLI. 4 + This module provides the Anthropic Claude backend for the ``muse-agents`` CLI. 6 5 """ 7 6 8 7 from __future__ import annotations ··· 25 24 # Default values are now handled internally 26 25 _DEFAULT_MODEL = CLAUDE_SONNET_4 27 26 _DEFAULT_MAX_TOKENS = 8096 * 2 28 - 29 - 30 - def setup_logging(verbose: bool) -> logging.Logger: 31 - """Return app logger configured for ``verbose``.""" 32 - if verbose: 33 - logging.basicConfig(level=logging.DEBUG) 34 - os.environ["ANTHROPIC_LOG"] = "debug" 35 - else: 36 - logging.basicConfig(level=logging.INFO) 37 - return logging.getLogger(__name__) 38 27 39 28 40 29 class ToolExecutor: ··· 369 358 raise 370 359 371 360 372 - async def run_prompt( 373 - prompt: str, 374 - *, 375 - config: Optional[Dict[str, Any]] = None, 376 - on_event: Optional[Callable[[dict], None]] = None, 377 - persona: str = "default", 378 - ) -> str: 379 - """Convenience helper to run ``prompt`` (alias for run_agent).""" 380 - return await run_agent(prompt, config=config, on_event=on_event, persona=persona) 381 - 382 - 383 361 __all__ = [ 384 362 "run_agent", 385 - "run_prompt", 386 - "setup_logging", 387 363 ]
+3 -32
muse/google.py
··· 1 1 #!/usr/bin/env python3 2 2 """Gemini backed agent implementation. 3 3 4 - This module exposes :class:`AgentSession` for interacting with Google's Gemini 5 - API. It is utilised by the unified ``muse-agents`` CLI. 4 + This module provides the Google Gemini backend for the ``muse-agents`` CLI. 6 5 """ 7 6 8 7 from __future__ import annotations ··· 24 23 # Default values are now handled internally 25 24 _DEFAULT_MODEL = GEMINI_FLASH 26 25 _DEFAULT_MAX_TOKENS = 8192 27 - 28 - 29 - def setup_logging(verbose: bool) -> logging.Logger: 30 - """Return app logger configured for ``verbose``.""" 31 - 32 - if verbose: 33 - logging.basicConfig(level=logging.DEBUG) 34 - else: 35 - logging.basicConfig(level=logging.INFO) 36 - 37 - return logging.getLogger(__name__) 38 26 39 27 40 28 class ToolLoggingHooks: ··· 119 107 return result 120 108 121 109 session.call_tool = wrapped # type: ignore[assignment] 122 - 123 - async def call_filtered_tool(self, name: str, arguments: dict | None = None) -> Any: 124 - """Call a tool through the session with logging.""" 125 - if not self.session: 126 - raise RuntimeError("Session not attached") 127 - return await self.session.call_tool(name=name, arguments=arguments) 128 110 129 111 130 112 async def run_agent( ··· 287 269 callback.emit(thinking_event) 288 270 289 271 text = response.text 272 + if not text: 273 + raise RuntimeError("Model returned empty response") 290 274 callback.emit({"event": "finish", "result": text}) 291 275 return text 292 276 except Exception as exc: ··· 301 285 raise 302 286 303 287 304 - async def run_prompt( 305 - prompt: str, 306 - *, 307 - config: Optional[Dict[str, Any]] = None, 308 - on_event: Optional[Callable[[dict], None]] = None, 309 - persona: str = "default", 310 - ) -> str: 311 - """Convenience helper to run ``prompt`` (alias for run_agent).""" 312 - return await run_agent(prompt, config=config, on_event=on_event, persona=persona) 313 - 314 - 315 288 __all__ = [ 316 289 "run_agent", 317 - "run_prompt", 318 - "setup_logging", 319 290 ]
-25
muse/openai.py
··· 13 13 import json 14 14 import logging 15 15 import os 16 - import sys 17 16 import time 18 17 import traceback 19 18 from typing import Any, Callable, Dict, Optional ··· 87 86 _DEFAULT_MAX_TURNS = int(os.getenv("OPENAI_AGENT_MAX_TURNS", "64")) 88 87 89 88 LOG = logging.getLogger("muse.openai") 90 - 91 - 92 - def setup_logging(verbose: bool = False) -> logging.Logger: 93 - level = logging.DEBUG if verbose else logging.INFO 94 - logging.basicConfig(level=level, stream=sys.stdout) 95 - return LOG 96 89 97 90 98 91 def _now_ms() -> int: ··· 492 485 pass 493 486 494 487 495 - async def run_prompt( 496 - prompt: str, 497 - *, 498 - config: Optional[Dict[str, Any]] = None, 499 - on_event: Optional[Callable[[dict], None]] = None, 500 - persona: str = "default", 501 - ) -> str: 502 - """Alias for run_agent for CLI parity.""" 503 - return await run_agent( 504 - prompt, 505 - config=config, 506 - on_event=on_event, 507 - persona=persona, 508 - ) 509 - 510 - 511 488 __all__ = [ 512 489 "run_agent", 513 - "run_prompt", 514 - "setup_logging", 515 490 ]