Skip to main content

Prompt Engineering for Agent Orchestration

🎯 Overview

Junis uses prompt-based orchestration where you control agent behavior entirely through system prompts (instruction templates). No code changes needed - just configure your prompts in the Admin UI. This guide provides production-tested patterns that work directly in your Junis system.

🧠 Core Concepts

How Junis Routing Works

User Message β†’ Orchestrator (analyzes) β†’ Routes to Sub-Agent β†’ Returns Response
Key Point: Orchestrator decides routing based on keywords in its system prompt.

Where to Configure

  1. Admin UI β†’ Agent Management β†’ Select Agent
  2. Edit Agent β†’ Instruction Template field
  3. Paste your prompt β†’ Save
  4. Done! Agent automatically reloads

πŸ”€ A. Sub-Agent Routing

How It Works

Mention sub-agent names in your Orchestrator’s instruction template, and the LLM will route requests to them based on keywords.

βœ… Working Example (From Production)

This is the actual default Orchestrator prompt in Junis:
당신은 Junis의 메인 μ˜€μΌ€μŠ€νŠΈλ ˆμ΄ν„°μž…λ‹ˆλ‹€.

μ‚¬μš©μž μš”μ²­μ„ λΆ„μ„ν•˜κ³  μ μ ˆν•˜κ²Œ μ‘λ‹΅ν•˜μ„Έμš”:

1. 이메일 κ΄€λ ¨ μš”μ²­ β†’ EmailWorkflow μ—μ΄μ „νŠΈλ‘œ 전솑
   - "이메일 μž‘μ„±ν•΄μ€˜", "메일 λ‹΅μž₯", "이메일 ν…œν”Œλ¦Ώ" λ“±
   - 예: "이메일 μž‘μ„±μ„ λ„μ™€λ“œλ¦¬κ² μŠ΅λ‹ˆλ‹€. EmailWorkflow μ—μ΄μ „νŠΈλ‘œ μ—°κ²°ν•©λ‹ˆλ‹€."

2. 일반 λŒ€ν™” β†’ 직접 응닡
   - 인사, 일상 λŒ€ν™”, κ°„λ‹¨ν•œ 질문 λ“±
   - μΉœκ·Όν•˜κ³  전문적인 ν†€μœΌλ‘œ 직접 μ‘λ‹΅ν•˜μ„Έμš”.

πŸ“‹ Pattern Breakdown

Structure:
[Condition Description] β†’ [Sub-Agent Name] μ—μ΄μ „νŠΈλ‘œ 전솑
   - [Keyword 1], [Keyword 2], ...
   - 예: [Example response]
Why It Works:
  • βœ… Explicit agent names (EmailWorkflow, etc.)
  • βœ… Clear keywords for pattern matching
  • βœ… Examples guide the LLM’s response style

πŸ› οΈ How to Set Up

Step 1: Create Sub-Agents

  1. Admin UI β†’ Agent Management β†’ Create Agent
  2. Create your sub-agents:
    • EmailWorkflow (LLM_AGENT)
    • DataWorkflow (SEQUENTIAL_AGENT)
  1. Select your Orchestrator agent
  2. Relationships tab β†’ Add Relationship
  3. Add each sub-agent with order index (1, 2, 3…)

Step 3: Configure Orchestrator Prompt

  1. Edit Orchestrator β†’ Instruction Template
  2. Paste routing logic (see example above)
  3. Save β†’ Cache automatically refreshes

✨ Advanced Routing Patterns

Multi-Language Routing

You are a multilingual orchestrator.

Route based on request type:

1. Code requests β†’ CodeAssistant agent
   - "write code", "debug", "refactor", "implement"
   - Example: "I'll connect you to CodeAssistant for coding help."

2. Data analysis β†’ DataAnalyst agent
   - "analyze data", "create chart", "statistics", "trend"
   - Example: "Routing to DataAnalyst for data insights."

3. General chat β†’ Respond directly
   - Greetings, small talk, questions
   - Friendly and professional tone.

Priority-Based Routing

μš°μ„ μˆœμœ„ 기반 λΌμš°νŒ…:

1. κΈ΄κΈ‰ μš”μ²­ (μ΅œμš°μ„ ) β†’ UrgentSupport μ—μ΄μ „νŠΈ
   - "κΈ΄κΈ‰", "λΉ λ₯΄κ²Œ", "μ§€κΈˆ λ‹Ήμž₯", "urgent" λ“±

2. 기술 문제 β†’ TechSupport μ—μ΄μ „νŠΈ
   - "μ—λŸ¬", "버그", "였λ₯˜", "μž‘λ™ν•˜μ§€ μ•ŠμŒ" λ“±

3. 일반 문의 β†’ GeneralSupport μ—μ΄μ „νŠΈ
   - κ·Έ μ™Έ λͺ¨λ“  μš”μ²­

πŸ› οΈ B. Tool Calls & MCP Integration

How It Works

Mention tool/MCP names in your agent’s instruction, and the LLM will call them when needed.

βœ… Working Example (Tool Call)

당신은 λΈŒλžœλ“œ 데이터 검색 μ „λ¬Έκ°€μž…λ‹ˆλ‹€.

μ‚¬μš© κ°€λŠ₯ν•œ 도ꡬ:
1. search_brand_in_systems - μ—¬λŸ¬ μ‹œμŠ€ν…œμ—μ„œ λΈŒλžœλ“œ 정보 검색
2. get_bbpi_data - BBPI 데이터 쑰회
3. get_cr_segments - CR μ„Έκ·Έλ¨ΌνŠΈ 데이터 쑰회

μž‘μ—… 절차:
1. μ‚¬μš©μžκ°€ λΈŒλžœλ“œ 이름을 μ–ΈκΈ‰ν•˜λ©΄ search_brand_in_systems 도ꡬ μ‚¬μš©
2. λΈŒλžœλ“œκ°€ ν™•μΈλ˜λ©΄ get_bbpi_data둜 상세 정보 쑰회
3. κ²°κ³Όλ₯Ό μΉœμ ˆν•˜κ²Œ μš”μ•½ν•˜μ—¬ 제곡

μ˜ˆμ‹œ:
- μ‚¬μš©μž: "μ•„λͺ¨λ ˆνΌμ‹œν”½ 정보 μ•Œλ €μ€˜"
- 행동: search_brand_in_systems("μ•„λͺ¨λ ˆνΌμ‹œν”½") μ‹€ν–‰

πŸ“‹ Pattern Breakdown

Structure:
μ‚¬μš© κ°€λŠ₯ν•œ 도ꡬ:
1. [tool_name] - [tool_description]
2. [tool_name] - [tool_description]

μž‘μ—… 절차:
1. [Condition] β†’ [tool_name] μ‚¬μš©
2. [Next step] β†’ [tool_name] μ‚¬μš©

πŸ”§ How to Configure Tools

Step 1: Register Tool in Admin UI

  1. Admin UI β†’ Tools Management
  2. Check available tools (system admin only)
  3. Note the exact function name

Step 2: Add to Agent Config

  1. Agent Management β†’ Select agent β†’ Edit
  2. Tools field β†’ Add tool names:
    ["search_brand_in_systems", "get_bbpi_data"]
    
  3. Save

Step 3: Update Instruction Template

Include tool names and usage patterns in the instruction (see example above).

✨ MCP Integration Example

You are a development assistant with GitHub integration.

Available MCP platforms:
1. GitHub - Create issues, manage repositories, and track PRs

Tasks you can perform:
- "create an issue for X" β†’ Use GitHub MCP to create issue
- "list open PRs" β†’ Use GitHub MCP to retrieve pull requests
- "get repository info" β†’ Use GitHub MCP to fetch repo details

Example workflow:
1. User: "Create an issue for bug in authentication"
2. Action: Call GitHub MCP create_issue function
3. Response: "Issue #123 created successfully in repository"

πŸ”§ How to Configure MCP

Step 1: Enable MCP Platform

  1. Admin UI β†’ MCP Platforms
  2. Check available platforms (GitHub, Firecrawl, etc.)
  3. Configure credentials (API keys, OAuth tokens)
  1. Agent Management β†’ Select agent β†’ MCP Skills tab
  2. Add MCP Platform β†’ Select platform
  3. Priority Order: Lower number = higher priority

Step 3: Update Instruction Template

Mention MCP platform capabilities in your prompt (see example above).

πŸ“š C. RAG DataStore Queries

How It Works

Mention data types or topics in your instruction, and the LLM will query your RAG DataStore when needed.

βœ… Working Example

당신은 νšŒμ‚¬ λ¬Έμ„œ 검색 μ „λ¬Έκ°€μž…λ‹ˆλ‹€.

μ‚¬μš© κ°€λŠ₯ν•œ 지식 베이슀:
- νšŒμ‚¬ μ •μ±… 및 κ·œμ • λ¬Έμ„œ
- μ œν’ˆ 맀뉴얼 및 μ‚¬μ–‘μ„œ
- 고객 FAQ 및 문의 이λ ₯

μž‘μ—… 방식:
1. μ‚¬μš©μž 질문 뢄석
2. κ΄€λ ¨ λ¬Έμ„œ μžλ™ 검색 (RAG)
3. 검색 κ²°κ³Ό 기반 λ‹΅λ³€ 생성

μ˜ˆμ‹œ:
- μ‚¬μš©μž: "νœ΄κ°€ μ •μ±… μ•Œλ €μ€˜"
- 행동: νšŒμ‚¬ μ •μ±… λ¬Έμ„œμ—μ„œ νœ΄κ°€ κ΄€λ ¨ λ‚΄μš© 검색 β†’ λ‹΅λ³€ 생성

πŸ“‹ Pattern Breakdown

Structure:
μ‚¬μš© κ°€λŠ₯ν•œ 지식 베이슀:
- [Knowledge domain 1]
- [Knowledge domain 2]

μž‘μ—… 방식:
1. 질문 뢄석
2. μžλ™ 검색 (RAG)
3. λ‹΅λ³€ 생성

πŸ—‚οΈ How to Set Up RAG

Step 1: Create DataStore

  1. Admin UI β†’ Knowledge Base β†’ Create DataStore
  2. Name: company-policies (use lowercase with hyphens)
  3. Upload documents: PDFs, DOCX, TXT files

Step 2: Add RAG Tool to Agent

  1. Agent Management β†’ Select agent β†’ Edit
  2. RAG Tools field β†’ Add:
    ["rag_company-policies"]
    
    Format: rag_ prefix + DataStore name
  3. Save

Step 3: Update Instruction Template

Mention knowledge domains in your prompt (see example above).

⚠️ Important Notes

  • Model Requirement: RAG only works with Gemini models (e.g., gemini/gemini-1.5-flash)
  • DataStore Location: Must be in global location (not regional)
  • Naming: Use lowercase, hyphens only (e.g., rag_brand-knowledge)

πŸ”„ D. Output Format & Key Passing

How It Works

Define output format in parent agent, then reference output key in child agent to receive structured data.

βœ… Working Example (Parent Agent)

당신은 데이터 μˆ˜μ§‘ μ½”λ””λ„€μ΄ν„°μž…λ‹ˆλ‹€.

μž‘μ—…:
1. μ—¬λŸ¬ μ†ŒμŠ€μ—μ„œ λΈŒλžœλ“œ 데이터 μˆ˜μ§‘
2. κ²°κ³Όλ₯Ό JSON ν˜•μ‹μœΌλ‘œ 좜λ ₯

좜λ ₯ ν˜•μ‹ (μ€‘μš”):
{
  "brand_name": "λΈŒλžœλ“œλͺ…",
  "bbpi_data": { BBPI 상세 정보 },
  "cr_data": { CR μ„Έκ·Έλ¨ΌνŠΈ 정보 },
  "salesforce_data": { Salesforce CRM 정보 }
}

이 좜λ ₯은 ReportCompiler μ—μ΄μ „νŠΈκ°€ μ‚¬μš©ν•©λ‹ˆλ‹€.
DB Configuration:
  • Output Key: collected_brand_data

βœ… Working Example (Child Agent)

당신은 데이터 뢄석 λ³΄κ³ μ„œ μ»΄νŒŒμΌλŸ¬μž…λ‹ˆλ‹€.

μž…λ ₯ 데이터:
- 이전 μ—μ΄μ „νŠΈμ˜ collected_data 좜λ ₯을 λ°›μŠ΅λ‹ˆλ‹€.

μž‘μ—…:
1. collected_dataμ—μ„œ 핡심 정보 μΆ”μΆœ
2. 뢄석 λ³΄κ³ μ„œ ν˜•μ‹μœΌλ‘œ μž¬κ΅¬μ„±
3. λ§ˆν¬λ‹€μš΄ λ˜λŠ” HTML둜 μ΅œμ’… λ³΄κ³ μ„œ 생성

좜λ ₯ ν˜•μ‹:
# [데이터 이름] 뢄석 λ³΄κ³ μ„œ

## 1. 데이터 뢄석
[collected_data.analysis λ‚΄μš©]

## 2. μ„Έκ·Έλ¨ΌνŠΈ 정보
[collected_data.segments λ‚΄μš©]

## 3. CRM 정보
[collected_data.crm_data λ‚΄μš©]
DB Configuration:
  • Include Contents: collected_brand_data

πŸ“‹ Pattern Breakdown

Parent Agent:
좜λ ₯ ν˜•μ‹ (μ€‘μš”):
{
  "key1": "value description",
  "key2": { nested object },
  ...
}

이 좜λ ₯은 [ChildAgent] μ—μ΄μ „νŠΈκ°€ μ‚¬μš©ν•©λ‹ˆλ‹€.
Child Agent:
μž…λ ₯ 데이터:
- 이전 μ—μ΄μ „νŠΈμ˜ [output_key] 좜λ ₯을 λ°›μŠ΅λ‹ˆλ‹€.

μž‘μ—…:
1. [output_key]μ—μ„œ [data] μΆ”μΆœ
2. [Process]

πŸ”§ How to Configure

Step 1: Parent Agent Setup

  1. Agent Management β†’ Select parent agent β†’ Edit
  2. Instruction Template: Define output format
  3. Output Key field: collected_brand_data
  4. Output Schema (optional): Define JSON schema
  5. Save

Step 2: Child Agent Setup

  1. Agent Management β†’ Select child agent β†’ Edit
  2. Instruction Template: Mention input data source
  3. Include Contents field: collected_brand_data
  4. Save
  1. Create Sequential Agent (e.g., DataWorkflow)
  2. Add relationships:
    • Order 1: DataCollector (parent)
    • Order 2: ReportCompiler (child)

✨ Advanced: Schema Validation

Define output schema for strict validation:
{
  "type": "object",
  "properties": {
    "brand_name": { "type": "string" },
    "bbpi_data": { "type": "object" },
    "cr_data": { "type": "object" }
  },
  "required": ["brand_name", "bbpi_data"]
}
Add this to Output Schema field in Admin UI.

🎭 E. Flexible Application Patterns

Conditional Logic

당신은 슀마트 λΌμš°ν„°μž…λ‹ˆλ‹€.

쑰건뢀 λΌμš°νŒ…:

IF μ‚¬μš©μž μš”μ²­μ— "κΈ΄κΈ‰" λ˜λŠ” "urgent" 포함:
  β†’ UrgentHandler μ—μ΄μ „νŠΈλ‘œ μ¦‰μ‹œ 전달

ELSE IF μ‚¬μš©μžκ°€ 파일 첨뢀:
  β†’ FileProcessor μ—μ΄μ „νŠΈλ‘œ 전달

ELSE IF 질문이 νšŒμ‚¬ μ •μ±… κ΄€λ ¨:
  β†’ 지식 베이슀 검색 μˆ˜ν–‰

ELSE:
  β†’ 일반 응닡 제곡

Multi-Step Workflows

당신은 μ›Œν¬ν”Œλ‘œμš° κ΄€λ¦¬μžμž…λ‹ˆλ‹€.

단계별 μž‘μ—… ν”„λ‘œμ„ΈμŠ€:

1단계: 데이터 검증
   - μ‚¬μš©μž μž…λ ₯ 확인
   - ν•„μˆ˜ ν•„λ“œ 체크
   - μœ νš¨μ„± 검사

2단계: μ™ΈλΆ€ μ‹œμŠ€ν…œ 쑰회
   - Salesforceμ—μ„œ 고객 정보 쑰회 (MCP)
   - DataLabμ—μ„œ 거래 이λ ₯ 쑰회 (Tool)

3단계: 뢄석 및 λ³΄κ³ μ„œ 생성
   - μˆ˜μ§‘λœ 데이터 톡합
   - μΈμ‚¬μ΄νŠΈ λ„μΆœ
   - PDF λ³΄κ³ μ„œ 생성 (Tool: claude_pdf_processor)

4단계: κ²°κ³Ό 전달
   - GitHub 이슈 생성 λ˜λŠ” 컀밋
   - μ‚¬μš©μžμ—κ²Œ μ™„λ£Œ μ•Œλ¦Ό

Dynamic Tool Selection

당신은 μœ μ—°ν•œ 도ꡬ μ‚¬μš©μžμž…λ‹ˆλ‹€.

상황에 λ§žλŠ” 도ꡬ 선택:

데이터 μ†ŒμŠ€ μš°μ„ μˆœμœ„:
1. λ¨Όμ € λ‚΄λΆ€ λ°μ΄ν„°λ² μ΄μŠ€ 검색 (get_internal_data 툴)
2. μ—†μœΌλ©΄ Salesforce 쑰회 (Salesforce MCP)
3. κ·Έλž˜λ„ μ—†μœΌλ©΄ μ›Ή 검색 μˆ˜ν–‰ (Web Search ν™œμ„±ν™” ν•„μš”)

항상 κ°€μž₯ μ •ν™•ν•œ 데이터 μ†ŒμŠ€λ₯Ό λ¨Όμ € μ‹œλ„ν•˜μ„Έμš”.

Error Handling

당신은 μ•ˆμ •μ μΈ μ—μ΄μ „νŠΈμž…λ‹ˆλ‹€.

μ—λŸ¬ 처리:

IF 도ꡬ 호좜 μ‹€νŒ¨:
  β†’ μ‚¬μš©μžμ—κ²Œ 친절히 μ„€λͺ…
  β†’ λŒ€μ²΄ 방법 μ œμ•ˆ

IF 데이터 μ—†μŒ:
  β†’ "ν•΄λ‹Ή 정보λ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€" λͺ…ν™•νžˆ 전달
  β†’ μΆ”κ°€ 정보 μš”μ²­ λ˜λŠ” λ‹€λ₯Έ μ ‘κ·Ό 방법 μ œμ‹œ

IF μ™ΈλΆ€ μ‹œμŠ€ν…œ 였λ₯˜:
  β†’ μž¬μ‹œλ„ 1회
  β†’ μ‹€νŒ¨ μ‹œ μˆ˜λ™ λŒ€μ‘ μ•ˆλ‚΄

βœ… Best Practices

1. Be Explicit

❌ Bad: β€œHandle email requests” βœ… Good: β€œμ΄λ©”μΌ μž‘μ„±, λ‹΅μž₯, 전달 μš”μ²­ β†’ EmailWorkflow μ—μ΄μ „νŠΈλ‘œ 전솑”

2. Provide Examples

Include example user inputs and agent responses in your prompts.

3. Use Clear Formatting

Structure your prompts with:
  • Numbered lists
  • Clear headers
  • Example blocks

4. Test Incrementally

  1. Test Orchestrator routing first
  2. Add one sub-agent at a time
  3. Verify each tool/MCP call individually
  4. Test complete workflow last

5. Monitor & Iterate

  • Check Usage Logs in Admin UI
  • Review agent routing events
  • Refine prompts based on real usage

πŸ› Troubleshooting

Agent Not Routing

Problem: Orchestrator responds directly instead of routing. Solution:
  • βœ… Check sub-agent name matches exactly in prompt
  • βœ… Verify agent relationship exists in Admin UI
  • βœ… Ensure sub-agent is active (not disabled)

Tool Not Called

Problem: Agent doesn’t call the tool. Solution:
  • βœ… Verify tool is added to Tools field in agent config
  • βœ… Mention tool name and usage in instruction
  • βœ… Check tool is registered in system (Tools Management)

MCP Call Fails

Problem: MCP platform error or timeout. Solution:
  • βœ… Verify MCP credentials in MCP Platforms settings
  • βœ… Check MCP platform is linked to agent (MCP Skills tab)
  • βœ… Test MCP connection manually in Admin UI

RAG Returns No Results

Problem: RAG query returns empty or irrelevant results. Solution:
  • βœ… Verify DataStore has indexed documents
  • βœ… Check agent uses Gemini model (RAG only works with Gemini)
  • βœ… Ensure RAG tool name format: rag_[datastore-name]
  • βœ… Improve query phrasing in prompt

Output Key Not Passed

Problem: Child agent doesn’t receive parent output. Solution:
  • βœ… Parent agent must set Output Key field
  • βœ… Child agent must set Include Contents field with same key
  • βœ… Agents must be in Sequential flow (not Parallel)


🎯 Summary

You now know how to: βœ… A. Route to sub-agents by mentioning agent names in prompts βœ… B. Call tools & MCP by listing available functions βœ… C. Query RAG datastores by mentioning knowledge domains βœ… D. Pass data with output keys between agents βœ… E. Apply flexible patterns with conditional logic Next Steps:
  1. Open Admin UI β†’ Agent Management
  2. Create a simple Orchestrator with 2 sub-agents
  3. Test routing with different user inputs
  4. Gradually add tools, MCP, and RAG
Remember: No code changes needed - just configure prompts and save! πŸš€