Agentic Browser

AI agent for web automation and scraping, designed to plan, execute, and verify actions across any website

Service specific prompts

Introduction#

Prompt chains for GitHub, YouTube, website Q&A, and similar services: context packing, output format, and failure behavior.

Project structure#

The repository organizes prompts, services, and FastAPI routers per domain. Prompts define the instruction templates and chains; services orchestrate ingestion, context assembly, and LLM invocation; routers expose HTTP endpoints for each service.

Core components#

  • GitHub prompt system: Builds a chain that merges repository summary, file tree, and content with a user question and optional chat history. It enforces strict reliance on provided context and uses Markdown formatting.
  • Website prompt system: Merges server-fetched and client-rendered contexts, prioritizing client-side content for dynamic and authenticated views. Provides guidelines for summaries, structure, links/media, metadata, and formatting.
  • YouTube prompt system: Assembles a transcript-based context (with error handling) and applies a focused schema for summaries, duration, stats, themes, sentiment, and recommendations.
  • React agent prompt: Supplies a tool-use instruction template for agents that rely on tool availability and structured reasoning.
  • Browser automation prompt: Defines a precise JSON action plan for Chrome extension automation, including DOM manipulation and tab/window control actions, with strong constraints and examples.

Architecture overview#

The system follows a consistent pattern:

  • Routers validate and parse requests, then delegate to services.
  • Services ingest domain-specific data (repository, website content, YouTube transcripts), assemble context, and invoke prompt chains.
  • Prompts define the instruction template and optional context assembly via Runnable chains.
  • Responses are normalized and returned through routers.

Detailed component analysis#

GitHub integration prompts#

  • Prompt template: System role, repository summary, file tree, relevant content, optional chat history, explicit guidelines, and formatting rules.
  • Input variables: tree, summary, content, question, chat_history.
  • Chain composition: RunnableParallel extracts inputs; PromptTemplate formats; LLM client executes; StrOutputParser returns text.
  • Parameter handling: Router validates presence of url and question; service passes chat_history as a string; optional attached file triggers direct GenAI SDK usage.
  • Response formatting: Markdown with code blocks and bullet lists; strict adherence to provided context.
  • Error handling: Dedicated error messages for invalid URLs, accessibility, token limit exceeded, and general failures.
  • Optimization: Truncates repository content when using GenAI SDK to fit payload limits; preserves concise summaries and trees.

Website analysis prompts#

  • Prompt template: Dual-context guidance (server-fetched vs client-rendered), explicit preference for client context, and detailed guidelines for summaries, structure, links/media, metadata, tables, and math formatting.
  • Input variables: server_context, client_context, question, chat_history.
  • Chain composition: RunnableParallel builds inputs; PromptTemplate + LLM client; StrOutputParser.
  • Parameter handling: Router validates url and question; service converts client HTML to markdown; chat_history assembled as a string; optional attached file bypasses chain and uses GenAI SDK.
  • Response formatting: Plain markdown with bullet points, tables, and LaTeX for math.
  • Error handling: Generalized error message on processing failure; client context fallback when unavailable.

YouTube processing prompts#

  • Prompt template: Focused assistant role for YouTube video questions, guidelines for summary, duration, stats, themes, sentiment, and recommendations, and strict scope limitations.
  • Input variables: context (transcript), question, chat_history.
  • Chain composition: RunnableParallel with a get_context function that fetches and cleans subtitles/transcripts; PromptTemplate + LLM client; StrOutputParser.
  • Parameter handling: Router validates url and question; service optionally uploads attached file via GenAI SDK; chat_history passed as string.
  • Response formatting: Plain markdown with bullet points, tables, and LaTeX.
  • Error handling: Known error detection for transcript retrieval; returns empty context when errors occur; service wraps exceptions and returns plain messages.

React agent prompt#

  • Template: Instructional prompt for agents that use tools, framing the question, listing available tools, and instructing to use tools to gather information.
  • Purpose: Pairs with the broader React agent orchestration (covered elsewhere) as the tool-use instruction.

Browser automation prompt#

  • Template: Detailed instruction for generating JSON action plans for Chrome extension automation. Includes DOM manipulation and tab/window control actions, selector guidance, search URL construction, and strict output rules.
  • Chain composition: ChatPromptTemplate piped to LLM; response parsed via StrOutputParser.
  • Parameter handling: Router constructs a user prompt from goal, target URL, DOM structure, and constraints; service sanitizes and validates JSON action plan.

Dependency analysis#

  • Routers depend on models and services to handle requests and responses.
  • Services depend on prompts for chain composition and on domain tools for context ingestion.
  • Prompts depend on the LLM client abstraction and LangChain components for formatting and parsing.

Performance considerations#

  • Context size management:
  • GitHub service truncates repository content when using GenAI SDK to avoid payload limits.
  • Website service assembles concise server and client contexts; client context is preferred but fallback is supported.
  • YouTube service cleans transcripts and falls back to empty context on known errors.
  • Token limits and retries:
  • GitHub service detects token limit exceeded and suggests narrowing the scope.
  • Browser automation limits DOM preview entries to reduce token usage.
  • Streaming and latency:
  • Chains are synchronous in current implementation; consider streaming responses at routers/services for long-running prompts.
  • Model selection:
  • Services support passing llm_options to prompt builders for model tuning.

Troubleshooting guide#

  • GitHub
  • Invalid repository URL: Returns guidance to use the repository root.
  • Access issues (404/clone): Requests public repository verification.
  • Token limit exceeded: Advises focusing on specific files/directories.
  • Website
  • General processing error: Returns a friendly message to retry.
  • Client HTML missing: Falls back to server context; client context is optional.
  • YouTube
  • Transcript retrieval errors: Known error messages detected and handled ; returns empty context.
  • LLM invocation errors: Wrapped with a plain message.
  • Browser automation
  • JSON validation failures: Validation returns problems; endpoint returns structured error response.
  • React agent
  • Attached file upload failures: Logs and returns a plain message; otherwise normal operation.

Conclusion#

Ground every answer in fetched context, demand the format you parse, and fail loudly when context is empty. Shared patterns beat one-off prompt files that drift.