{"enrichment":{"faq":[{"a":"PydanticAI's RunContext provides access to dependencies through the ctx parameter in your tool functions. Define your dependencies as a dataclass or Pydantic model, set deps_type on your Agent, then pass an instance via agent.run(deps=your_deps). Inside tools, retrieve them with ctx.deps to access database connections, API clients, or other resources safely and with full type checking.","q":"How to use RunContext in PydanticAI?"},{"a":"The deps_type parameter on Agent[DepsType, OutputType] specifies the type of dependencies your agent accepts. It enables generic type safety: define a dataclass with your resources (database, logger, API client), pass deps_type=YourDepsClass to Agent(), then PydanticAI enforces that only matching dependency instances reach your tools and instructions.","q":"What is deps_type in pydantic-ai-dependency-injection?"},{"a":"Create a dataclass holding your database connection, set it as deps_type on your Agent, then pass an instance to agent.run(deps=db_deps). In your tool functions, access it via ctx.deps.db_connection. This pattern works for any external resource\u2014API clients, loggers, configuration\u2014keeping them injectable and testable.","q":"How do I pass a database connection to a PydanticAI agent?"},{"a":"Use the generic Agent[DepsType, OutputType] pattern: define deps_type with a strongly-typed dataclass or Pydantic model, and PydanticAI validates at runtime that dependencies match. Your IDE and type checker see ctx.deps as the exact type you declared, eliminating runtime surprises and enabling autocomplete on injected resources.","q":"How can pydantic-ai-dependency-injection achieve type safety?"},{"a":"Create a test version of your deps dataclass with mock objects (mock database, stub API client), then pass it to agent.run(deps=test_deps) in your test. Since deps_type is generic, you can swap implementations without changing agent code, making unit tests fast and isolated.","q":"How do I mock and override dependencies for testing?"},{"a":"PydanticAI's RunContext pattern (ctx.deps) decouples tools from initialization logic: dependencies are bound once at agent.run() time and available to all tools without threading parameters through function signatures. This keeps tool code clean and enables consistent, type-safe access across your entire agent workflow.","q":"What's the difference between accessing ctx.deps vs passing deps directly?"}],"shadow_tags":["context-injection","resource-management","type-checked-deps","agent-initialization","testing-mocks","async-clients","dataclass-patterns","tool-access-control"],"summary_rewrite":"This skill shows how to wire external dependencies into PydanticAI agents through RunContext and the deps_type parameter. Learn to define dependencies as dataclasses or Pydantic models, access them safely in tools and instructions, and maintain full type safety across your agent code."},"files":[{"bytes":5246,"path":"plugins/beagle-ai/skills/pydantic-ai-dependency-injection/SKILL.md","sha256":"2525fac9934ffe7898cbc3fbd1faa2d83f85c619879ed772e87d1ebe406d1bae","url":"https://skillfed.io/files/existential-birds/beagle/pydantic-ai-dependency-injection/28312dd5/SKILL.md"}],"id":"existential-birds/beagle/pydantic-ai-dependency-injection","links":{"html":"https://skillfed.io/existential-birds/beagle/pydantic-ai-dependency-injection","md":"https://skillfed.io/existential-birds/beagle/pydantic-ai-dependency-injection.md","repo":"https://github.com/existential-birds/beagle"},"meta":{"agents_supported":[],"first_seen":"2026-07-28","forks":10,"language":"TypeScript","last_updated":"2026-07-21","license":"Apache-2.0","name":"pydantic-ai-dependency-injection","publisher":"existential-birds","stars":74},"relations":{"similar":[{"id":"existential-birds/beagle/pydantic-ai-common-pitfalls"},{"id":"existential-birds/beagle/pydantic-ai-agent-creation"},{"id":"DougTrajano/pydantic-ai-skills/pydanticai-docs"},{"id":"existential-birds/beagle/pydantic-ai-testing"},{"id":"itechmeat/llm-code/pydantic-ai"},{"id":"cline/skills/building-pydantic-ai-agents"},{"id":"pydantic/skills/building-pydantic-ai-agents"},{"id":"existential-birds/beagle/pydantic-ai-tool-system"},{"id":"existential-birds/beagle/pydantic-ai-model-integration"},{"id":"alinaqi/maggy/agentic-development"}]},"slug":{"owner":"existential-birds","repo":"beagle","skill":"pydantic-ai-dependency-injection"},"version":"28312dd5"}
