MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / formatPrompt

Function formatPrompt

packages/agent-runtime/src/templates/strings.ts:40–151  ·  view source on GitHub ↗
(
  params: {
    prompt: string
    fileContext: ProjectFileContext
    agentState: AgentState
    tools: readonly string[]
    spawnableAgents: AgentTemplateType[]
    agentTemplates: Record<string, AgentTemplate>
    intitialAgentPrompt?: string
    additionalToolDefinitions: () => Promise<
      ProjectFileContext['customToolDefinitions']
    >
    logger: Logger
  } & ParamsExcluding<
    typeof getAgentTemplate,
    'agentId' | 'localAgentTemplates'
  >,
)

Source from the content-addressed store, hash-verified

38}
39
40export async function formatPrompt(
41 params: {
42 prompt: string
43 fileContext: ProjectFileContext
44 agentState: AgentState
45 tools: readonly string[]
46 spawnableAgents: AgentTemplateType[]
47 agentTemplates: Record<string, AgentTemplate>
48 intitialAgentPrompt?: string
49 additionalToolDefinitions: () => Promise<
50 ProjectFileContext['customToolDefinitions']
51 >
52 logger: Logger
53 } & ParamsExcluding<
54 typeof getAgentTemplate,
55 'agentId' | 'localAgentTemplates'
56 >,
57): Promise<string> {
58 const {
59 fileContext,
60 agentState,
61 tools: _tools,
62 spawnableAgents: _spawnableAgents,
63 agentTemplates,
64 intitialAgentPrompt,
65 additionalToolDefinitions: _additionalToolDefinitions,
66 logger,
67 } = params
68 let { prompt } = params
69
70 const { messageHistory } = agentState
71 function isUserInputMessage(message: Message): message is UserMessage & {
72 content: [TextPart, ...any[]]
73 } {
74 return (
75 message.role === 'user' &&
76 message.content[0].type === 'text' &&
77 parseUserMessage(message.content[0].text) !== undefined
78 )
79 }
80 const lastUserMessage = messageHistory.findLast(isUserInputMessage)
81 const lastUserInput = lastUserMessage
82 ? parseUserMessage(lastUserMessage.content[0].text)
83 : undefined
84
85 const agentTemplate = agentState.agentType
86 ? await getAgentTemplate({
87 ...params,
88 agentId: agentState.agentType,
89 localAgentTemplates: agentTemplates,
90 })
91 : null
92
93 const toInject: Record<PlaceholderValue, () => string | Promise<string>> = {
94 [PLACEHOLDER.AGENT_NAME]: () =>
95 agentTemplate ? agentTemplate.displayName || 'Unknown Agent' : 'Buffy',
96 [PLACEHOLDER.CURRENT_DATE]: () => formatCurrentDate(new Date()),
97 [PLACEHOLDER.FILE_TREE_PROMPT_SMALL]: () =>

Callers 1

getAgentPromptFunction · 0.85

Calls 7

parseUserMessageFunction · 0.90
getAgentTemplateFunction · 0.90
getProjectFileTreePromptFunction · 0.90
getGitChangesPromptFunction · 0.90
getSystemInfoPromptFunction · 0.90
escapeStringFunction · 0.90
formatCurrentDateFunction · 0.85

Tested by

no test coverage detected