Source-linked AI summary

Sema Code: Decoupling AI Coding Agents into Programmable, Embeddable Infrastructure

Huacan Wang, Jie Zhou, Ningyan Zhu, Shuo Zhang, Feiyu Chen, Jiarou Wu, Ge Chen, Chen Liu, Wangyi Chen, Xiaofeng Mou, Yi Xu

arXiv:2604.11045v1cs.SE

TL;DR

AI coding systems are difficult to reuse across heterogeneous environments because their reasoning engines are locked into product-specific delivery forms. Sema Code decouples the engine into a programmable, embeddable library with mechanisms for shared execution, coordination, permissions, context, and ecosystem integration. The same unmodified Sema Core powers both a VSCode extension and the multi-channel SemaClaw platform, demonstrating delivery-agnostic operation across two product forms.

  • Problem

    Existing AI coding solutions couple core reasoning with specific client layers, creating barriers to embedding, model replacement, and multi-channel deployment.

  • Method

    Sema Code publishes a decoupled agent engine as a standalone library and supports it with mechanisms for isolation, queuing, context management, multi-agent coordination, permissions, and extensibility.

  • Results

    The unmodified Sema Core simultaneously powers a VSCode extension and SemaClaw, with behavioral differences implemented entirely at the client layer.

  • Takeaways & Limitations

    The deployments provide evidence that one reasoning kernel can serve fundamentally different delivery forms while composing the engine’s mechanisms without interference.

  • Takeaways & Limitations

    Validation covers only two product forms, and scale stress testing remains incomplete; production workloads with hundreds of concurrent users may expose unobserved bottlenecks.

Abstract

from arXiv · show

AI coding agents have become central to developer workflows, yet every existing solution locks its reasoning capabilities within a specific delivery form, such as a CLI, IDE plugin, or web application. This limitation creates systemic barriers when enterprises attempt to reuse these capabilities across heterogeneous engineering environments. To address this challenge, we present Sema Code, an open AI coding framework built on the principle of being embeddable, pluggable, and framework-first. Sema Code completely decouples the core agent engine from all client layers, publishing it as a standalone npm library that any runtime can drive programmatically. Built around this architecture, we designed eight key mechanisms: multi-tenant engine isolation, FIFO input queuing with safe session reconstruction, adaptive context compression, multi-agent collaborative scheduling, intelligent Todo-based process management, four-layer asynchronous permission control, three-tier ecosystem integration spanning MCP, Skills, and Plugins, and a background task framework with separated execution and observation privileges. These mechanisms collectively address the engineering challenges of transforming a complex agent engine into a shared, programmable core. Demonstrating its architectural versatility, the same Sema Core engine simultaneously powers a VSCode extension and a multi-channel messaging gateway, which we name SemaClaw, to unify agent interactions across platforms such as Telegram and Feishu. These represent two fundamentally different product forms sharing an identical reasoning kernel, differing only at the client layer.

1 Introduction

AI coding agents remain tied to product-specific interfaces, limiting enterprise reuse across runtimes and channels. Sema Code addresses this by decoupling a programmable core engine from client layers and adding mechanisms for safe, extensible operation.

  • Motivation: Existing AI coding solutions couple reasoning capabilities to CLI, IDE-plugin, or application form factors, hindering enterprise embedding and model replacement.These constraints also make multi-channel delivery difficult.
  • Core proposal: Sema Code reframes AI coding as an embeddable engine by publishing the decoupled agent core as a standalone library.The framework is designed for programmatic use rather than a single prescribed user experience.
  • Architecture: The architecture separates client, core engine, and service layers, with the complete agent packaged as a UI-free npm library supporting direct, WebSocket, and gRPC integration.This separation allows different runtimes to consume the same core capabilities.
  • Engine mechanisms: Three engine mechanisms address concurrent-workload safety and resource efficiency: multi-tenant isolation, FIFO input queuing with session reconstruction, and adaptive context compression.Together they target state safety and context/resource management in shared operation.
  • Runtime mechanisms: The runtime adds collaborative multi-agent scheduling, Todo-based process management, and background tasks that separate execution privileges from observation rights.Sub-agents use isolated state spaces and shared interrupt control.
  • Security and ecosystem: A four-layer asynchronous permission system and a three-tier MCP, Skill, and Plugin ecosystem extend security and capability integration.The framework also includes a multi-model adaptation layer for capability integration.

2 Related Work

Prior AI coding systems advance agent reasoning, tool use, research frameworks, and developer-facing products, but leave production-grade embeddability insufficiently addressed. Sema Code targets this gap by separating a standalone core engine from client delivery forms.

  • Foundational capabilities: Foundational systems such as Chain-of-Thought, ReAct, and Toolformer established intermediate reasoning, environment interaction, and tool invocation for modern agents.
  • Developer-facing general frameworks: OpenHands supports multi-agent coding with sandbox environments and custom tools, but production concerns including tenant isolation, permissions, and cross-language integration remain under-addressed.
  • End-user product systems: Claude Code offers a capable terminal-based assistant and plugin ecosystem, yet its CLI-integrated core is difficult to embed across heterogeneous delivery environments.
  • End-user product systems: Editor plugins and autonomous coding systems provide distinct interaction models, while editor form factors constrain private deployment and model replacement.
  • Sema Code: Sema Code publishes its core engine as a standalone library, combining runtime-independent embeddability with production engineering from tenant isolation through ecosystem integration.

3 System Design

Sema Code separates clients from a UI-free core engine and addresses multi-tenant state, concurrency, and context-lifecycle challenges through layered isolation, FIFO dispatch, and adaptive context management.

  • Architecture: Sema Core separates client, core engine, and service layers, keeping reasoning, tool invocation, and state management independent of UI or runtime assumptions.Clients render or forward typed engine events, while WebSocket and gRPC interfaces support cross-language integration.
  • Multi-tenant isolation: A single process can serve multiple tenants by binding each engine instance to isolated resources propagated across asynchronous execution boundaries.The design addresses conversation-history leakage and cross-instance interrupt collisions without requiring separate OS processes.
  • Hierarchical state partitioning: Within a session, agent-local state is isolated while global permissions and abort control remain shared for coordinated termination.Local state includes execution status, conversation history, Todos, and file-read timestamps; global state includes file-modification rights and a centralized abort controller.
  • Input queuing: FIFO dispatch buffers inputs during processing and semantically batches consecutive text messages while executing system commands individually.The policy reduces fragmented context and redundant API calls while preserving command isolation.
  • Context lifecycle: Adaptive context management treats the finite context window as an information-preservation problem rather than relying on naive truncation.The approach retains critical entities while discarding verbose tool outputs and intermediate reasoning traces.

4 Agent Runtime

Sema Code organizes complex agentic execution around bounded multi-agent delegation, deterministic progress tracking, interrupt-safe scheduling, and background execution for long-running operations.

  • Runtime architecture: The runtime uses hierarchical execution to decompose tasks across agents, track progress, and offload long-running operations without blocking interaction.Its architecture combines multi-agent scheduling, structured process management, and a dedicated background execution engine.
  • Multi-agent scheduling: One-level delegation lets the main agent create sub-agents while preventing sub-agents from spawning further agents, bounding call depth and resource consumption.Each sub-agent receives an isolated state space and shares only the abort controller with the main agent.
  • Interrupt control: The runtime propagates interrupts across four execution boundaries, from post-inference dispatch through recursion termination.It cancels pending operations, skips pre-execution tools, distinguishes refusals from aborts during execution, and flushes unfinished results before collapsing recursion.
  • Tool scheduling: Read-only batches execute concurrently, whereas any batch containing a write operation is serialized to prevent race conditions.The policy applies concurrency selectively to file and content searches while protecting edits and shell executions.
  • Process management: A deterministic Todo state machine preserves task descriptions during subset updates and permits at most one active subtask.Unknown identifiers trigger full replacement, while known identifiers update lifecycle states without reproducing LLM phrasing changes.
  • Background tasks: Background execution separates long-running task execution from observation so the dialog loop can resume immediately.Tasks transition deterministically among running, successful, failed, and forcefully stopped states, with bounded concurrency and retained history.

5 Security and Ecosystem

Sema Code combines layered permission decisions with asynchronous approval and a three-tier extension ecosystem that distinguishes infrastructure, behavior, and workflow capabilities.

  • Permission architecture: The permission system maps file edits, shell commands, Skills, and MCP calls to specialized evaluation layers reflecting their distinct risk profiles.The decision function P : O × C → {allow, deny, request} evaluates each operation under the current session context.
  • Shell security: Shell execution receives the most stringent treatment because command injection creates the acute security challenge.Its two-stage evaluation combines deterministic whitelist checking with LLM-assisted static analysis for obfuscated injection patterns.
  • Asynchronous approval: Asynchronous approval suspends execution through an event bus while allowing IDEs, web interfaces, and messaging bots to provide native consent interactions.The engine resumes only after a user decision or global abort signal, and sub-agents inherit parent permission boundaries.
  • Three-tier ecosystem: MCP services, Skills, and Plugins operate at infrastructure, behavior, and workflow granularities, respectively, so a unified extension layer would mismatch their capabilities.MCP wraps external systems, Skills reshape reasoning, and Plugins orchestrate multi-step processes across tool invocations.
  • Marketplace integration: The marketplace supports one-click discovery and installation for MCP services, Skills, and command or hook Plugins.Installed MCP services and Skills load through configuration, while Plugins support enable, disable, and update operations without session restart.
  • Model adaptation: Built-in Anthropic and OpenAI-compatible adapters normalize provider-specific streaming features into a unified event protocol.The adapter layer reconciles Anthropic thinking events with the opaque reasoning-token behavior of OpenAI-compatible endpoints.

6 Deployment Validation

Sema Code’s deployment validation shows that one Sema Core engine powers distinct product forms without engine changes, while each client exercises complementary mechanisms. The two deployments also expose practical scope boundaries, including limited scale validation and single-process operation.

  • Two Deployments: The VSCode extension and SemaClaw use the same Sema Core engine while differing in client interfaces and deployment topology.The extension targets individual developers; SemaClaw serves multiple concurrent users through messaging channels and a Web UI.
  • Architectural Observations: Neither product required changes to Sema Core; UI rendering, channel routing, permission dialogs, and deployment topology remain client-layer concerns.This supports the claim that the three-layer separation makes the engine delivery-agnostic.
  • Architectural Observations: The deployments provide complementary mechanism coverage: VSCode stresses context compression and background tasks, whereas SemaClaw stresses multi-tenant isolation and FIFO queuing.Together, they cover all eight mechanisms, and both run on the same engine binary without feature flags or conditional paths.
  • Client Integration: Client developers use Sema Core’s public API and typed event stream without handling internal state management, compression logic, or permission machinery.The extension implements event rendering and VSCode UI, while SemaClaw implements channel adapters and a multi-session manager.
  • Limitations: Validation covers only two product forms, lacks large-scale stress testing, and leaves horizontal scaling across multiple engine instances unaddressed.Additional limitations concern context-compression quality and unbenchmarked WebSocket/gRPC behavior under adversarial network conditions.

7 Conclusion

Sema Code presents AI coding capabilities as programmable infrastructure by decoupling the core engine from client layers and exposing eight mechanisms through a public API. Its conclusion argues for embeddable, open ecosystems and identifies retrieval, richer coordination, and distributed scheduling as future directions.

  • Contributions: Sema Code elevates AI coding from product-locked features to programmable infrastructure by fully decoupling the core engine from client layers.The framework makes embedding an agent comparable to adding an npm dependency.
  • Contributions: Eight mechanisms address engineering challenges involved in exposing an agent engine as a public API, from multi-tenant isolation to background task execution.The mechanisms span state management, coordination, permissions, ecosystem integration, and task execution.
  • Implications: The paper argues that embeddability and open ecosystems are the next critical evolution for AI coding frameworks.It envisions coding capabilities integrated as engines into existing toolchains rather than locked inside specific products.
  • Future Work: Future work targets vector-retrieval context management, state-sharing multi-agent coordination, and distributed scheduling across engine instances.These directions extend historical recall, cooperation, and elastic production deployment.
Loading 2604.11045v1…