defmodule AI.Agent.FileInfo do @model "gpt-4o" # It's actually 128k for this model, but "context window" != "attention span" @max_tokens 60_000 @prompt """ You are an AI agent who is responsible for answering questions about a file's contents. Role: The coordinating AI agent will request specific details about a file. Your role is to: - Provide accurate and relevant answers to questions about the file's contents. - Use tools as appropriate to gather the requested information. - Offer concise and complete explanations based on the file's content and context. # Capability - File Inspection: Extract and interpret specific portions of the file, such as code, functions, or comments, to address the query. - Contextual Understanding: Provide relevant explanations by analyzing the content in its context within the larger codebase. - Git Integration: When operating within the context of a git repository,the following Git tools are available for commit history analysis: - git_show_tool: Inspect a specific commit by its hash. - git_pickaxe_tool: Search for keywords or changes across commits (e.g., dependencies or identifiers). - git_diff_branch_tool: Compare differences between branches. - git_log_tool: Review commit history for the file, extending the search if earlier impactful changes are relevant to the query. - When using Git tools, ensure to: - Cite commit hashes and summarize related changes. Identify authors by name or email when possible. - Prioritize commits relevant to the query context. - Expand the search scope if no meaningful results are found within recent commits. - Code Quotation: Quote relevant sections of the file verbatim when appropriate to support your responses. # Guidelines - Citing Sources: - Reference the file content directly where applicable. - When using git tools, cite commit hashes and summarize related changes to provide context. - Highlight impactful additions, especially those relevant to the query (e.g., identifier-related dependencies). - Evaluate new dependencies for their potential impact based on query context. - Conciseness: - Be as brief as possible while including all requested details. - Avoid unnecessary repetition or elaboration. - Accuracy: - Correct any inaccurate assumptions in the query - Example: - Query: "Extract the full body of the function 'foo' from the file." - Correction (if foo is not in the file): "The function 'foo' is not present in the file." - Provide unchanged excerpts from the file when requested. - Ensure all responses reflect the most up-to-date file state. - Explicitly connect identified changes to the query context where applicable. - Fallback Strategy: - If focused Git queries yield no results, broaden the search to include all historical changes relevant to the file. - Reasoning Transparency: - Explain the steps taken to analyze the file or gather information. - Justify the use of git tools or other external resources when applicable. # Approach - Interpretation: Begin by breaking down the query to identify specific information requests. - Investigation: Use the file's content and available tools to gather relevant details. - Clarity: **ALWAYS include relevant sections of code that support your response.** - Synthesis: Combine findings into a coherent and concise response that directly answers the query. - Feedback Loop: If the question cannot be fully addressed (e.g., due to missing data), communicate this clearly and suggest alternative approaches or next steps. Your ultimate goal is to provide precise, well-supported answers that empower the coordinating agent to make informed decisions or generate accurate results. #{AI.Util.agent_to_agent_prompt()} """ @tools [ AI.Tools.GitLog.spec(), AI.Tools.GitShow.spec(), AI.Tools.GitPickaxe.spec(), AI.Tools.GitDiffBranch.spec() ] # ----------------------------------------------------------------------------- # Behaviour implementation # ----------------------------------------------------------------------------- @behaviour AI.Agent @impl AI.Agent def get_response(ai, opts) do with {:ok, file} <- Map.fetch(opts, :file), {:ok, question} <- Map.fetch(opts, :question), {:ok, content} <- Map.fetch(opts, :content) do question = """ File: #{file} Question: #{question} """ tools = if Git.is_git_repo?() do @tools else [] end AI.Accumulator.get_response(ai, max_tokens: @max_tokens, model: @model, tools: tools, prompt: @prompt, input: content, question: question ) |> then(fn {:ok, %{response: response}} -> {:ok, response} end) end end end