@github_agent.tool async def get_file_content(ctx: RunContext[GitHubDeps], github_url: str, file_path: str) -> str: """Get the content of a specific file from the GitHub repository. Args: ctx: The context. github_url: The GitHub repository URL. file_path: Path to the file within the repository. Returns: str: File content as a string. """ match = re.search(r'github\.com[:/]([^/]+)/([^/]+?)(?:\.git)?$', github_url) if not match: return "Invalid GitHub URL format" owner, repo = match.groups() headers = {'Authorization': f'token {ctx.deps.github_token}'} if ctx.deps.github_token else {} response = await ctx.deps.client.get( f'https://raw.githubusercontent.com/{owner}/{repo}/main/{file_path}', headers=headers ) if response.status_code != 200: # Try with master branch if main fails response = await ctx.deps.client.get( f'https://raw.githubusercontent.com/{owner}/{repo}/master/{file_path}', headers=headers ) if response.status_code != 200: return f"Failed to get file content: {response.text}" return response.text