Framework Integrations¶
Only official framework adapters are accepted by Optimizer. Install the matching extra:
langchain, langgraph, or google-adk (Python 3.10+). Factories must return real framework
objects. Mapping functions configure framework inputs, configuration, session state, and outputs.
tunarag.integrations.google_adk.GoogleADKAdapter ¶
GoogleADKAdapter(runner: Any = None, *, factory: Callable[[Candidate], Any] | None = None, state_mapper: Callable[[Candidate], Mapping[str, Any]] | None = None, output_mapper: Callable[[Any], Any] | None = None, events_mapper: Callable[[Sequence[Any]], Any] | None = None, token_prices: TokenPrices | None = None, identity: Any = None)
Evaluate a Google ADK runner in a fresh session for every sample and retry.
Candidate parameters become initial session state. Use a factory when changing
an agent's model, tools, or graph requires constructing a new framework runner.
By default the output is {"answer": final_text, "tool_responses": [...]} so tool
results (for example retrieved passages) are available to evaluators and RAGAS.
Source code in src/tunarag/integrations/google_adk.py
run
async
¶
run(candidate: Candidate, example: Any) -> tuple[Any, tuple[UsageRecord, ...]]
Consume runner events, capture usage, and remove the temporary session.
Source code in src/tunarag/integrations/google_adk.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
fingerprint ¶
Describe integration semantics without sessions or provider credentials.
Source code in src/tunarag/integrations/google_adk.py
Google ADK creates and deletes a fresh session for each sample, including retries. Candidate
parameters become session state; agent construction settings require a runner factory. The
application owns and closes runners. For LangGraph checkpointing, map each evaluation to its own
thread instead of reusing a production conversation. Include model, corpus, prompt, and mapper
revisions in adapter identity so cache and resume do not mix pipeline versions.
LangChain and LangGraph¶
runnables ¶
Adapters for LangChain runnables and compiled LangGraph graphs.
RunnableConfigMapper
module-attribute
¶
RunnableConfigMapper = Callable[[Candidate], Mapping[str, Any] | None]
TokenPrices
module-attribute
¶
Model name -> (USD per 1M input tokens, USD per 1M output tokens).
LangChainAdapter ¶
LangChainAdapter(runnable: Any = None, *, factory: RunnableFactory | None = None, input_key: str = 'question', input_mapper: RunnableInputMapper | None = None, config_mapper: RunnableConfigMapper | None = None, output_mapper: RunnableOutputMapper | None = None, usage_mapper: RunnableUsageMapper | None = None, capture_message_usage: bool = True, token_prices: TokenPrices | None = None, identity: Any = None)
Bases: _RunnableAdapter
Expose a LangChain runnable through TunaRAG's standard adapter contract.
Source code in src/tunarag/integrations/runnables.py
LangGraphAdapter ¶
LangGraphAdapter(graph: Any = None, *, factory: RunnableFactory | None = None, input_key: str = 'question', input_mapper: RunnableInputMapper | None = None, config_mapper: RunnableConfigMapper | None = None, output_mapper: RunnableOutputMapper | None = None, usage_mapper: RunnableUsageMapper | None = None, capture_message_usage: bool = True, token_prices: TokenPrices | None = None, identity: Any = None)
Bases: _RunnableAdapter
Expose a compiled LangGraph graph through TunaRAG's adapter contract.
Source code in src/tunarag/integrations/runnables.py
validate_token_prices ¶
validate_token_prices(prices: TokenPrices | None) -> dict[str, tuple[float, float]] | None
Check a model -> (input, output) USD-per-million-token price table.
Source code in src/tunarag/integrations/runnables.py
priced_usage ¶
priced_usage(component: str, model: str | None, input_tokens: int | None, output_tokens: int | None, prices: Mapping[str, tuple[float, float]] | None) -> UsageRecord
Build a model-call usage record, estimating cost when the model has a price.
The component name stays stable (callers filter on it); the model only selects the price.
Source code in src/tunarag/integrations/runnables.py
warn_missing_identity ¶
Source code in src/tunarag/integrations/runnables.py
runnable_identity ¶
Best-effort structural identity: type, wrapped functions, graph nodes, chain steps.
Source code in src/tunarag/integrations/runnables.py
MLflow¶
mlflow ¶
Optional post-commit MLflow tracking mirror.
MLflowClient ¶
MLflowCallback ¶
MLflowCallback(store: SQLiteStore, *, experiment_id: str = '0', tracking_uri: str | None = None, tags: Mapping[str, str] | None = None, client: MLflowClient | None = None)
Mirror committed study events into one low-level MLflow run.
Source code in src/tunarag/integrations/mlflow.py
on_event
async
¶
on_event(event: StudyEvent) -> None
Mirror one durable event after gathering committed local state.