Skip to content

Commit 947eece

Browse files
dividedminddustinbyrne
authored andcommitted
feat: Add AppMap recording recommendations to explain
1 parent 116bda7 commit 947eece

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

packages/navie/src/agents/explain-agent.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,47 @@ classDiagram
263263
</example>
264264
`;
265265

266+
const APPMAP_HINT_PROMPT = `
267+
## Recommending AppMap Recordings
268+
269+
As you provide your response, consider whether your statements could be improved if the user had provided
270+
additional context in the form of an AppMap recording - essentially, runtime traces. If so, add an
271+
\`appmap\` XML tag following the statement that could be improved. This will prompt the user to provide such information; the tags
272+
will be used to provide specialized UI to help the user accomplish this task. You can use many of these tags spread throughout your
273+
response text as you need, each associated with a specific statement that could be made more accurate with this data.
274+
275+
Provide a \`prompt\` attribute to the \`appmap\` tag, which will be used to initiate a conversation with an assistant to help
276+
the user create AppMaps. You should use \`@observe\` prefix in the prompt which will choose the correct assistant.
277+
278+
You can additionally provide a \`reasoning\` attribute to the \`appmap\` tag, which will be used to explain
279+
how an AppMap recording would provide additional context.
280+
281+
Make sure that all recommendations for AppMap recordings are kept only to these tags ONLY. Do not mention AppMap in the
282+
running text of your response unless the user has specifically asked for it.
283+
284+
Note recording AppMaps is currently only supported in Ruby, Python, Java and JavaScript (server-side only, ie. Node.js) applications.
285+
Do not recommend AppMap recordings for other languages or environments.
286+
287+
Examples:
288+
289+
\`\`\`markdown
290+
If you suspect redundant calls to the \`foo\` method, you should investigate further. Check to see if the \`foo\` method is being
291+
called more than once <appmap prompt="@observe record and analyze tests that involve the foo method to identify redundant calls" />.
292+
This will help you identify and eliminate inefficiencies in your code.
293+
\`\`\`
294+
295+
\`\`\`markdown
296+
The JWT token might not be properly stored or transmitted in subsequent requests. This could lead to issues with authentication
297+
or session management. <appmap reasoning="An AppMap trace would show if the JWT token is being properly included in request headers after login"
298+
prompt="@observe record a session including the authentication flow, focusing on login and subsequent API requests to verify token usage" />. Ensuring proper token handling is critical for secure communication.
299+
\`\`\`
300+
301+
\`\`\`markdown
302+
Authentication filters can sometimes cause unexpected behavior. Check that your authentication filter isn't accidentally catching the login endpoints themselves <appmap reasoning="An AppMap trace would reveal if the auth filter is intercepting login requests, causing a loop"
303+
prompt="@observe record both authenticated and unauthenticated HTTP requests, including login attempts, to identify potential filter misconfigurations" />. This will help you avoid potential infinite loops or access issues.
304+
\`\`\`
305+
`;
306+
266307
export default class ExplainAgent implements Agent {
267308
public temperature = undefined;
268309

@@ -284,6 +325,16 @@ export default class ExplainAgent implements Agent {
284325
if (hasLabel(options.contextLabels, ContextV2.ContextLabelName.GenerateDiagram))
285326
this.history.addEvent(new PromptInteractionEvent('agent', 'system', DIAGRAM_FORMAT_PROMPT));
286327

328+
if (
329+
// Do not prompt for AppMap recordings if the user is greeting or chatting.
330+
!options.contextLabels?.find((label) =>
331+
[ContextV2.ContextLabelName.Greeting, ContextV2.ContextLabelName.Chatting].includes(
332+
label.name
333+
)
334+
)
335+
)
336+
this.history.addEvent(new PromptInteractionEvent('agent', 'system', APPMAP_HINT_PROMPT));
337+
287338
this.history.addEvent(
288339
new PromptInteractionEvent(
289340
PromptType.Question,

packages/navie/test/agents/explain-agent.spec.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import ExplainAgent from '../../src/agents/explain-agent';
2-
import InteractionHistory, {
3-
ContextItemRequestor,
4-
isPromptEvent,
5-
} from '../../src/interaction-history';
62
import ApplyContextService from '../../src/services/apply-context-service';
73
import VectorTermsService from '../../src/services/vector-terms-service';
84
import LookupContextService from '../../src/services/lookup-context-service';
@@ -12,8 +8,8 @@ import { CHARACTERS_PER_TOKEN } from '../../src/message';
128
import { UserOptions } from '../../src/lib/parse-options';
139
import ContextService from '../../src/services/context-service';
1410
import MermaidFixerService from '../../src/services/mermaid-fixer-service';
15-
import mermaid from 'mermaid';
1611
import { ContextV2 } from '../../src/context';
12+
import InteractionHistory, { ContextItemRequestor } from '../../src/interaction-history';
1713

1814
describe('@explain agent', () => {
1915
let interactionHistory: InteractionHistory;
@@ -114,6 +110,11 @@ describe('@explain agent', () => {
114110
role: 'system',
115111
name: 'agent',
116112
},
113+
{
114+
type: 'prompt',
115+
role: 'system',
116+
name: 'agent',
117+
},
117118
{
118119
type: 'prompt',
119120
role: 'system',
@@ -202,6 +203,11 @@ describe('@explain agent', () => {
202203
role: 'system',
203204
name: 'agent',
204205
},
206+
{
207+
type: 'prompt',
208+
role: 'system',
209+
name: 'agent',
210+
},
205211
{
206212
type: 'prompt',
207213
role: 'system',

0 commit comments

Comments
 (0)