-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
171 lines (135 loc) · 5.62 KB
/
Copy pathconfig.py
File metadata and controls
171 lines (135 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""Global configuration, paths, environment setup, and logging for the Wcode agent."""
from dataclasses import dataclass, field
import logging
from logging.handlers import RotatingFileHandler
import os
from pathlib import Path
from dotenv import load_dotenv
from rich.logging import RichHandler
import litellm
litellm.suppress_debug_info = True
litellm.set_verbose = False
# Suppress third-party library logs — only business code logs are relevant
logging.getLogger("LiteLLM").setLevel(logging.WARNING)
logging.getLogger("litellm").setLevel(logging.WARNING)
logging.getLogger("httpcore").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
logging.getLogger("openai").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("asyncio").setLevel(logging.WARNING)
load_dotenv()
MY_MODEL = os.environ.get("MODEL", "deepseek/deepseek-v4-flash")
MAX_TOKENS = 8192
PERSIST_THRESHOLD = 30000
WORKDIR = Path.cwd()
# ── MCP servers ───────────────────────────────────────────────────────────
# Each entry defines an MCP server to launch at agent startup.
# The key is an arbitrary short name; tools will be exposed as
# ``mcp__<key>__<tool_name>``.
#
# command : str — executable (e.g. "python", "node", "my-server")
# args : list[str] — CLI arguments (e.g. ["-m", "mcp_server_fetch"])
# env : dict | None — extra env vars, or None to inherit
MCP_SERVERS: dict[str, dict] = {
"fetch": {
"command": "python",
"args": ["-m", "mcp_server_fetch"],
},
}
# ── Directories ──
SKILLS_DIR = WORKDIR / "skills"
MEMORY_DIR = WORKDIR / ".memory"
MEMORY_DIR.mkdir(exist_ok=True)
MEMORY_INDEX = MEMORY_DIR / "MEMORY.md"
TOOL_RESULTS_DIR = WORKDIR / ".task_outputs" / "tool-results"
TRANSCRIPT_DIR = WORKDIR / ".transcripts"
SESSIONS_DIR = WORKDIR / ".sessions"
LOGS_DIR = WORKDIR / "logs"
LOGS_DIR.mkdir(exist_ok=True)
# ── Configuration dataclass ────────────────────────────────────────────────
@dataclass
class WodeConfig:
"""Central configuration for the Wode agent.
All paths default to subdirectories of the current working directory.
Create an instance and override fields as needed, then pass it to
:class:`WodeApp`.
"""
model: str = "deepseek/deepseek-v4-flash"
max_tokens: int = 8192
persist_threshold: int = 30000
workdir: Path = field(default_factory=Path.cwd)
skills_dir: Path = field(default_factory=lambda: Path.cwd() / "skills")
memory_dir: Path = field(default_factory=lambda: Path.cwd() / ".memory")
sessions_dir: Path = field(default_factory=lambda: Path.cwd() / ".sessions")
mcp_servers: dict[str, dict] = field(default_factory=dict)
logs_dir: Path = field(default_factory=lambda: Path.cwd() / "logs")
# ── Logging ──
def setup_logging(
level: int = logging.INFO,
log_file: str | None = None,
file_level: int | None = None,
max_bytes: int = 10 * 1024 * 1024, # 10 MB
backup_count: int = 5,
) -> None:
"""Configure the root logger with RichHandler for console output and
RotatingFileHandler for file output.
Sets up a consistent logging format across all Wcode modules. Each module
obtains its own logger via ``logging.getLogger(__name__)`` and inherits
this configuration from the root logger.
Parameters
----------
level : int, optional
The root logger level. Defaults to ``logging.INFO``.
Use ``logging.DEBUG`` only when debugging third-party library issues.
log_file : str | None, optional
Path to the log file. If ``None``, defaults to
``logs/wode.log`` under the project root.
file_level : int | None, optional
Log level for the file handler. If ``None``, defaults to *level*
(same as console).
max_bytes : int, optional
Max size of each log file before rotation. Defaults to 10 MB.
backup_count : int, optional
Number of rotated backup files to keep. Defaults to 5.
"""
if log_file is None:
log_file = str(LOGS_DIR / "wcode.log")
root = logging.getLogger()
root.setLevel(level)
# Only add handlers once (idempotent guard)
if root.handlers:
return
# ── Console handler (rich) ──
console_handler = RichHandler(
rich_tracebacks=True,
markup=True,
show_time=True,
show_level=True,
show_path=False,
)
console_handler.setLevel(level)
console_fmt = logging.Formatter("%(message)s", datefmt="[%X]")
console_handler.setFormatter(console_fmt)
# ── File handler (plain text) ──
file_handler = RotatingFileHandler(
log_file,
maxBytes=max_bytes,
backupCount=backup_count,
encoding="utf-8",
)
file_handler.setLevel(file_level if file_level is not None else level)
file_fmt = logging.Formatter(
"[%(asctime)s] %(levelname)-8s %(name)s | %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
file_handler.setFormatter(file_fmt)
root.addHandler(console_handler)
root.addHandler(file_handler)
def get_logger(name: str | None = None) -> logging.Logger:
"""Return a logger for *name* (typically ``__name__`` from the calling module).
If logging hasn't been configured yet, calls ``setup_logging()`` first so
that every module gets a usable logger out of the box.
"""
if not logging.getLogger().handlers:
setup_logging()
return logging.getLogger(name)