This guide outlines best practices for high-code AI Agent applications, distilled from real-world development experience to help you build and deploy more efficiently.
This guide outlines best practices for high-code AI Agent applications, distilled from real-world development experience to help you build and deploy more efficiently.
Core requirements:
A step-by-step workflow for building high-code applications from scratch:
Choose the right tool type based on your use case:
✅ Multiple tools can be combined — e.g., Knowledge Base (domain expertise) + MCP Search Service (real-time info) → a fully featured, production-ready Agent.
Write high-quality MCP tool functions to improve tool selection and execution accuracy:
The
Each parameter must include a
Format tool results as plain-text summaries containing key context—avoid raw JSON or unstructured blobs.
Convert exceptions into human-readable, LLM-understandable messages—not raw stack traces.
Leverage two built-in console testing modes:
Follow these steps when promoting your high-code application to production:
Three frontend integration options are available—choose based on your needs:
💡 Recommendation: Use Direct Experience during development; choose Interaction Cards or Custom WebUI at delivery—based on complexity and branding needs.
Project Structure
Core requirements:
- The entry file must be named
main.py. - A
GET /healthendpoint must be provided. When using AgentScope Runtime, this endpoint is automatically registered—you do not need to implement it manually. - The default conversation endpoint path is
/process, conforming to the Agent API Protocol specification. - In
requirements.txt, dependencies must be pinned using==(e.g.,dashscope==1.20.14). Avoid version ranges like>=, as they cause inconsistent dependency resolution across builds—potentially leading to build failures or runtime inconsistencies. After local debugging succeeds, runpip freeze > requirements.txtto export exact versions.
Recommended Development Workflow
A step-by-step workflow for building high-code applications from scratch:
- Start from a template: When creating an application in the console, select an appropriate template (e.g., Basic Chat Agent, Tool-Calling Agent, or Deep Research Agent) to quickly obtain a runnable base project.
-
Local development & debugging: Download the template code locally, install dependencies per the
READMEincluded in the package, then run and debug locally: - Add tools: In the console’s Tools page, add required tools (e.g., Knowledge Base, MCP services), retrieve environment variables, and implement tool-calling logic in your code.
-
Build and deploy: Package your project as a
.whlfile and deploy it: -
Console testing: After successful deployment:
- Use the API Test Mode (right panel) to verify endpoints.
- Use the Text Chat Experience Mode (right panel) to validate multi-turn dialogue behavior and tool invocation.
-
Iterate and optimize: Adjust code based on test results and rapidly update deployment using:
Tool Selection Guide
Choose the right tool type based on your use case:
| Scenario | Recommended Tool | Description |
|---|---|---|
| Enterprise knowledge Q&A | Knowledge Base | Import product docs, FAQs, and user guides; enables precise retrieval. |
| External service integration | MCP Service | Prefer existing services from the MCP Plaza (e.g., search, finance data, enterprise lookup) to minimize custom development. |
| Multi-Agent orchestration | Application Component | Decompose complex tasks into specialized sub-agents (e.g., translation, summarization, analysis) and chain them via components. |
MCP Tool Development Best Practices
Write high-quality MCP tool functions to improve tool selection and execution accuracy:
✅ Precise tool descriptions
The name and description fields directly influence LLM tool selection. Descriptions should clearly state purpose, use cases, and expected inputs.
✅ Complete parameter documentation
Each parameter must include a Field(description=...) with clear details: format, valid range, and default value.
✅ Return structured, LLM-friendly output
Format tool results as plain-text summaries containing key context—avoid raw JSON or unstructured blobs.
✅ Friendly error handling
Convert exceptions into human-readable, LLM-understandable messages—not raw stack traces.
Testing & Debugging
Leverage two built-in console testing modes:
| Test Mode | Use Case | Recommendations |
|---|---|---|
| API Test | Debug custom endpoints, validate request/response formats, test paths/headers | Use early to verify connectivity and parameter correctness. Supports custom HTTP method, path, headers, and body. |
| Text Chat Experience | Simulate real user conversations, test multi-turn flow, verify tool triggering | Use mid-to-late stage for end-to-end validation. Focus on tool trigger accuracy and response quality. |
Debugging tips:
- Check runtime logs in the Logs tab of the Deployment page to diagnose tool call failures.
- Monitor call count, error rate, and response time in the Application Observability page to identify bottlenecks.
- Click Copy cURL Command to generate and run curl commands directly in your terminal.
- Enable Application Observability, and use the
@tracedecorator to track LLM latency and tool execution chains.
Production Deployment
Follow these steps when promoting your high-code application to production:
- Configure API Gateway: Create an API Gateway instance in the Gateway page. Set up a custom domain and routing rules to expose your service under a stable URL. ⚠️ Important: Your application’s deployment region must match the gateway’s region—otherwise routing will fail.
- Enable Token Authentication: In gateway settings, turn on Token-based auth to ensure only authorized requests access your API.
- Disable public test domain access: In the Triggers section of the Deployment page, toggle Disable Public Access to restrict traffic exclusively to your gateway domain.
-
Adjust resource specs: Scale vCPU, memory, and minimum instance count based on expected traffic. Set
min instances ≥ 1to avoid cold-start latency (~10–30 sec). For high-performance, stateful, or long-running tasks, consider Kubernetes (ACK) deployment—see Deployment Options. -
Enable Application Observability: Activate observability and instrument your code with
@traceto continuously monitor quality and performance.
Frontend Integration
Three frontend integration options are available—choose based on your needs:
| Option | Use Case | Details |
|---|---|---|
| Direct Experience | Quick validation, internal demos | Use the built-in Text Chat Experience mode—zero-code, instant UI. Ideal for early-stage functional validation. |
| Custom Interaction Card | Lightweight branding & UX tweaks | Define card UI directly in Python code; renders inside the chat window. No standalone frontend needed. See Spark Design Cards. |
| Custom WebUI | Full UI control, production-grade | Build a fully customized frontend using the Spark Design framework. Best for advanced UI requirements. See Spark Design Docs. |
Performance Optimization Tips
-
Use streaming responses: The Agent API Protocol supports Server-Sent Events (SSE) natively. Return results via
async yieldso users see output incrementally—greatly improving perceived responsiveness. -
Set minimum instances wisely: In production, set
min instances ≥ 1to eliminate cold-start delays. Note: Minimum instances incur continuous cost. -
Parallelize independent tool calls: When multiple unrelated tools are needed, use
asyncio.gather()to execute them concurrently—reducing total latency. - Cache frequent queries: In-memory cache static or infrequently updated results (e.g., knowledge base lookups, external API responses) to reduce redundant network calls.