Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions mini_agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
"""

from .agent import MiniAgent
from .llm import SimpleLLM
from .llm import SimpleLLM, LLMResponse
from .tools import ToolCollection, PythonExecutor, FileEditor, BashExecutor
from .schema import Message, Memory, AgentState
from .schema import Message, Memory, AgentState, Role

__all__ = [
"MiniAgent",
"SimpleLLM",
"SimpleLLM",
"LLMResponse",
"ToolCollection",
"PythonExecutor",
"FileEditor",
"BashExecutor",
"Message",
"Memory",
"AgentState"
"AgentState",
"Role",
]
5 changes: 4 additions & 1 deletion mini_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def __init__(
system_prompt: Optional[str] = None,
max_steps: int = 10
):
if max_steps < 1:
raise ValueError(f"max_steps must be >= 1, got {max_steps}")
self.name = name
self.llm = llm
self.tools = ToolCollection()
Expand Down Expand Up @@ -128,7 +130,8 @@ async def act(self) -> None:
# ε‡†ε€‡η»“ζžœζΆˆζ―
if result.success:
result_content = result.output
print(f"βœ… ε·₯ε…·ζ‰§θ‘ŒζˆεŠŸ: {result_content[:100]}...")
preview = result_content[:100] if result_content else "(empty)"
print(f"βœ… ε·₯ε…·ζ‰§θ‘ŒζˆεŠŸ: {preview}...")
else:
result_content = f"ι”™θ――: {result.error}"
print(f"❌ ε·₯ε…·ζ‰§θ‘Œε€±θ΄₯: {result.error}")
Expand Down
4 changes: 2 additions & 2 deletions mini_agent/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from enum import Enum
from typing import List, Optional, Dict, Any
from pydantic import BaseModel
from pydantic import BaseModel, Field


class Role(str, Enum):
Expand Down Expand Up @@ -39,7 +39,7 @@ def tool_message(cls, content: str, tool_call_id: str) -> "Message":


class Memory(BaseModel):
messages: List[Message] = []
messages: List[Message] = Field(default_factory=list)

def add_message(self, message: Message):
self.messages.append(message)
Expand Down
6 changes: 6 additions & 0 deletions mini_agent/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ class BashExecutor(BaseTool):

async def execute(self, command: str, **kwargs) -> ToolResult:
try:
import warnings
warnings.warn(
"BashExecutor uses shell=True which is a security risk. "
"Only use with trusted input.",
stacklevel=2,
)
Comment on lines +145 to +149

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid failing BashExecutor under warnings-as-errors

Emitting warnings.warn(...) inside BashExecutor.execute can make every bash call fail in environments that run with PYTHONWARNINGS=error or -W error (common in CI/tests): warn raises UserWarning, it is caught by the broad except Exception, and the method returns success=False before/without running the command. This turns a diagnostic warning into a functional regression for those runtimes.

Useful? React with πŸ‘Β / πŸ‘Ž.

result = subprocess.run(
command,
shell=True,
Expand Down
Loading