Agent Loop: The Core Reasoning Cycle
Every Expert response is driven by a sophisticated reasoning loop:Context Construction
Before each inference, the Runtime carefully assembles context for the Expert — this determines what the AI “knows” and what it “can do”:1
System persona injection
The Expert’s core persona (mental models, decision heuristics, expression style) is injected as system instructions, defining the AI’s “soul.”
2
History loading
Relevant messages are loaded from conversation history. When history gets too long, context compaction is automatically triggered (see Context Engine).
3
Memory retrieval
Long-term memories relevant to the current conversation are retrieved from the Expert’s memory graph, allowing the AI to remember user preferences and historical context.
4
Skill loading
Relevant skills are dynamically activated based on the conversation scenario — skills give the Expert specialized operational workflows for specific domains.
5
Tool declaration
Based on the Expert’s capability configuration and current mode, available tools are declared (code execution, file operations, web search, creative generation, etc.).
Streaming Output: Real-Time Interaction
Profy uses the Server-Sent Events (SSE) protocol for real-time streaming output. Users don’t need to wait for the AI to finish thinking — every token, every tool call, every intermediate state is pushed in real time:Multi-Turn Tool Execution
The power of an Expert lies in its ability to “get things done” like a human. In a single response, the AI may need to invoke multiple tools in sequence: After each tool call, the AI examines the result and decides the next step: continue executing, fix an error, or report back to the user. This “observe-decide-act” loop is the fundamental difference between an Agent and an ordinary chatbot.HITL: Human-in-the-Loop Confirmation
For sensitive operations (such as file deletion, external API calls, or payment operations), the Expert does not execute directly. It first presents the plan to the user and requests confirmation:1
AI proposes an action plan
The Expert recognizes that the upcoming operation may have irreversible effects, proactively pauses, and describes the plan.
2
User confirms or modifies
The user sees a confirmation card and can approve, modify parameters, or reject the operation.
3
Proceeds based on decision
Continues execution upon approval; switches to an alternative approach if rejected.
Token Budget Control
Each session has a token budget cap to prevent runaway inference consumption:- Input budget: Automatically triggers context compaction to stay within the model’s window
- Output budget: Automatically recovers and continues writing when a single response exceeds the limit (up to 3 times)
- Session total budget: Gracefully stops when cumulative consumption reaches the cap, rather than cutting off abruptly
The goal of budget control is not to “limit” the Expert’s capabilities, but to ensure predictable resource usage. When the budget is nearly exhausted, the Expert automatically switches to more concise response mode, ensuring every token counts.
Plugin-Based Tool System
The Runtime’s tool system is driven by declarative Manifests rather than hardcoded logic:Sandbox Tools
Code execution (bash), file read/write (read/write/edit), full-text search (grep/glob) — all running in isolated containers.
Creative Tools
Image generation, video generation, music creation, speech synthesis — calling specialized model APIs.
Knowledge Tools
Web search, webpage reading, external knowledge base connectors (Feishu/DingTalk/Yuque, etc.).
Memory Tools
Memory storage and retrieval — Experts can proactively remember important information and recall it in future conversations.
Delegated Execution: Cross-Expert Collaboration
One Expert can delegate specific subtasks to other Experts — like division of labor within a team: Delegated tasks execute asynchronously in the background without blocking the main conversation flow. Users see real-time task progress updates.Security Safeguards
The Runtime has multiple built-in security mechanisms to protect Expert creators’ intellectual property:- Prompt leak detection: Real-time monitoring of AI output; if system prompt fragments are detected leaking, they are automatically intercepted and replaced
- Skill content sanitization: Raw skill text returned by tools is replaced with safe summaries before being sent to the frontend
- Canary tokens: Invisible markers embedded in the system prompt make any copying behavior traceable
Performance Characteristics
The Runtime is a stateless service — all session state is stored externally (database + Redis), meaning it can scale horizontally to any concurrency level. If any Pod goes down, no user conversations are lost.

