Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
OPENAI_API_KEY=sk-xxxx
GITHUB_TOKEN=ghp_xxxx
# Optional model overrides (defaults work):
OPENAI_MODEL=gpt-4o

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,6 @@ runs/
logs/
dataset/
else/
artifacts/
artifacts/
_out/
notes.txt
37 changes: 28 additions & 9 deletions src/ai_agent/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from api.pipeline import RAGImagingPipeline
from utils.utils import _best_runnable_link
from .models import AgentToolSelection, ToolRunLog
from .tools.repo_info_tool import tool_repo_info, RepoInfoInput
from .tools.repo_info_tool import tool_repo_summary, RepoSummaryInput, coerce_github_url_or_none
from .tools.rerank_tool import tool_rerank, RerankInput
from .tools.search_tool import tool_search_tools, SearchToolsInput
from .tools.gradio_space_tool import tool_run_example, RunExampleInput
Expand Down Expand Up @@ -80,12 +80,32 @@ async def rerank(ctx: RunContext[AgentState], query: str, candidate_names: List[
# })
# return out.model_dump(mode="python")

@agent.tool(retries=2, prepare=cap_prepare)
@limit_tool_calls("repo_info", cap=2)
@agent.tool(retries=0, prepare=cap_prepare)
@limit_tool_calls("repo_info", cap=3)
async def repo_info(ctx: RunContext[AgentState], url: str):
out = tool_repo_info(RepoInfoInput(url=url))
ctx.deps.tool_calls.append({"tool": "repo_info", "url": url, "truncated": out.truncated})
return out.model_dump(mode="python")
norm_url = coerce_github_url_or_none(url)
if not norm_url:
payload = {
"invalid": True,
"reason": "NON_GITHUB_URL",
"hint": "Pass a GitHub repo URL or 'owner/repo' to repo_info(url).",
"original": url,
}
ctx.deps.tool_calls.append({"tool": "repo_info", "url": url, "skipped": True, "reason": "NON_GITHUB_URL"})
return payload

try:
out = tool_repo_summary(RepoSummaryInput(url=norm_url))
ctx.deps.tool_calls.append({"tool": "repo_info", "url": norm_url, "truncated": out.truncated})
return out.model_dump(mode="python")
except Exception as e:
ctx.deps.tool_calls.append({"tool": "repo_info", "url": norm_url, "error": str(e)})
return {
"invalid": True,
"reason": "FETCH_FAILED",
"url": norm_url,
"message": str(e),
}

@agent.tool(retries=2, prepare=cap_prepare)
@limit_tool_calls("resolve_demo_link", cap=3)
Expand Down Expand Up @@ -126,8 +146,7 @@ def run_agent(task: str, image_data_url: str | None = None, excluded: List[str]
short_meta = " ".join(x.strip() for x in image_meta.splitlines() if x.strip())
hidden_meta += "\n(Image Metadata: " + short_meta[:500] + ("…" if len(short_meta) > 500 else "") + ")"
prompt = task + extra_context + hidden_meta
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool call limit was increased from 6 to 10, but there's no comment explaining why this change was necessary. Given that repo_info can now be called up to 3 times per run, consider adding a brief comment explaining the rationale for this increase.

Suggested change
prompt = task + extra_context + hidden_meta
prompt = task + extra_context + hidden_meta
# Increased tool_calls_limit from 6 to 10 because repo_info can now be called up to 3 times per run.
# This ensures the agent has enough tool calls available for typical tasks.

Copilot uses AI. Check for mistakes.
log.info(f"Agent prompt: {prompt}")
result = agent.run_sync(prompt, deps=deps, output_type=ToolSelection, usage_limits=UsageLimits(tool_calls_limit=6)).output
result = agent.run_sync(prompt, deps=deps, output_type=ToolSelection, usage_limits=UsageLimits(tool_calls_limit=10)).output

# Convert tool call dicts into ToolRunLog entries
for tc in deps.tool_calls:
Expand All @@ -153,4 +172,4 @@ def run_agent(task: str, image_data_url: str | None = None, excluded: List[str]
tool_calls=tool_logs,
)

__all__ = ["run_agent", "agent"]
__all__ = ["run_agent", "agent"]
Loading