Skip to content

Linux philosophy optimization: complete project refactoring#3

Draft
Copilot wants to merge 2 commits into
copilot/review-project-code-optimizationfrom
copilot/complete-project-refactor
Draft

Linux philosophy optimization: complete project refactoring#3
Copilot wants to merge 2 commits into
copilot/review-project-code-optimizationfrom
copilot/complete-project-refactor

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 12, 2026

Applies the recommendations from docs/linux_philosophy_optimization.md — a systematic review of xAgent through the lens of Unix/Linux design principles. Changes span security hardening, dependency hygiene, observability decoupling, and filling in placeholder functionality.

🔴 High Priority

  • H1 — Logging pollution: Removed logging.basicConfig() from agent.py. Library code must never configure the root logger.
  • H2 — CORS security: AgentHTTPServer now emits SecurityWarning on allow_origins=["*"]; origins are configurable via server.cors.allow_origins in config.
  • H3 — Typo fix: Renamed upstach_vector_store.pyupstash_vector_store.py; old file kept as a one-line backward-compat re-export shim.
  • H4 — Structured error logging: Background memory task permanent failures now include structured extra fields (task_description, error, attempts); max_iter exhaustion returns a diagnostic message instead of a generic one.
  • H5 — DoS prevention: AgentInput HTTP fields now use pydantic.Field(ge=..., le=...) bounds (e.g. max_iter capped at 50) sourced from defaults.py.

🟡 Medium Priority

  • M1+M2 — Optional dependencies: langfuse and chromadb moved from required to optional in pyproject.toml. New extras: local, cloud, observability, dev, all.

  • M1 — Observability module: New xagent/observability/__init__.py provides @observe decorator and get_openai_client() — both transparent no-ops when Langfuse is absent.

    # agent.py — no longer imports langfuse directly
    from ..observability import observe, get_openai_client
    
    @observe
    async def chat(self, ...): ...
    self.client = get_openai_client(client)  # wraps with Langfuse if installed
  • M5 — Preview length: TOOL_RESULT_PREVIEW_LENGTH increased from 20 → 200 characters.

  • M8 — Magic numbers: New xagent/defaults.py is the single source of truth for all constants (timeouts, limits, TTLs); AgentConfig references these instead of inline literals.

🟢 Low Priority

  • L1 — Swarm implementation: Replaced the empty Swarm placeholder with a working implementation using Agent.as_tool(). Specialist agents register as tools on a coordinator; Swarm is now exported from the top-level xagent package.

    swarm = Swarm(agents=[researcher, writer])
    result = await swarm.run(task="Research and summarize quantum computing.")
  • L2 — YAML DSL: Added parse_dependencies_yaml() to workflow_dsl.py. GraphWorkflow now auto-detects YAML-format vs arrow-DSL dependency strings.

    dependencies:
      analyzer:
        - researcher
      writer:
        - analyzer

Tests

Added tests/test_refactoring.py with 20 tests covering all the above. All 37 tests pass; CodeQL reports 0 alerts.

Original prompt

基于 linux_philosophy_optimization.md
完成项目的完整重构


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: ZJCODE <5073837+ZJCODE@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor project based on linux philosophy optimization Linux philosophy optimization: complete project refactoring Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants