Skip to content

Improve consistency and DRY across Penelope targets and SDK telemetry integrations #2070

Description

@harry-rhesis

Summary

Address cross-cutting consistency gaps and DRY opportunities across the Penelope target implementations and SDK telemetry integrations, identified during the review of PR #2057.

Background / Context

PR #2057 (Pydantic AI integration) revealed several inconsistencies and duplication patterns that exist across all targets and integrations, not just Pydantic AI. These are best addressed in a separate PR to keep #2057 focused.

Deliverables

  • Add try/except ImportError guards in penelope/src/rhesis/penelope/targets/__init__.py so that missing optional dependencies (langchain, langgraph, pydantic-ai) degrade gracefully instead of breaking the entire import
  • Add native a_send_message() to LangChainTarget and LangGraphTarget (using ainvoke / arun) instead of relying on the base class thread-pool fallback, matching PydanticAITarget's pattern
  • Extract PatchState base class or factory from the duplicated AgentPatchState (pydantic_ai.py) and GraphPatchState (langgraph.py) into integrations/base.py
  • Add LLM-level child spans (ai.llm.invoke) inside Pydantic AI agent runs, matching the visibility LangChain/LangGraph provide for individual model calls within an agent run

Acceptance Criteria

  • import rhesis.penelope.targets succeeds on a minimal install without langchain, langgraph, or pydantic-ai
  • LangChainTarget and LangGraphTarget have native async paths that do not use asyncio.to_thread
  • GraphPatchState and AgentPatchState share a common base, reducing code duplication
  • Pydantic AI agent runs produce ai.llm.invoke child spans for individual model calls

Additional Context

Related to PR #2057: #2057

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions