Critic scorer
critic_scorer ¶
CriticScorer adapter for structured scoring with ADK critic agents.
This module provides the CriticScorer implementation that wraps ADK critic agents to provide structured scoring with feedback, dimension scores, and actionable guidance. The scorer implements the Scorer protocol, enabling integration with gepa-adk's evaluation and evolution workflows.
Also provides KISS and advanced critic output schemas with generic instruction templates for rapid critic agent development.
| ATTRIBUTE | DESCRIPTION |
|---|---|
CriticScorer | Adapter that wraps ADK critic agents for scoring. TYPE: |
SimpleCriticOutput | KISS schema with just score + feedback. TYPE: |
CriticOutput | Advanced schema with dimensions and guidance. TYPE: |
SIMPLE_CRITIC_INSTRUCTION | Generic instruction for simple critics. TYPE: |
ADVANCED_CRITIC_INSTRUCTION | Generic instruction for advanced critics. TYPE: |
normalize_feedback | Normalizes critic output to trial format. TYPE: |
Examples:
Basic usage with LlmAgent critic:
from pydantic import BaseModel, Field
from google.adk.agents import LlmAgent
from gepa_adk.adapters.critic_scorer import CriticScorer, CriticOutput
critic = LlmAgent(
name="quality_critic",
model="gemini-2.5-flash",
instruction="Evaluate response quality...",
output_schema=CriticOutput,
)
scorer = CriticScorer(critic_agent=critic)
score, metadata = await scorer.async_score(
input_text="What is Python?",
output="Python is a programming language.",
)
Note
This module wraps ADK critic agents to provide structured scoring. When using LlmAgent with output_schema, the agent can ONLY reply and CANNOT use any tools (ADK constraint). For evaluations requiring tool usage, use a SequentialAgent with tool-enabled agents before the output-constrained scorer.
SimpleCriticOutput ¶
Bases: BaseModel
flowchart TD
gepa_adk.adapters.critic_scorer.SimpleCriticOutput[SimpleCriticOutput]
click gepa_adk.adapters.critic_scorer.SimpleCriticOutput href "" "gepa_adk.adapters.critic_scorer.SimpleCriticOutput"
KISS schema for basic critic feedback.
This is the minimal schema for critic agents that only need to provide a score and text feedback. Use this for straightforward evaluation tasks where dimension breakdowns are not needed.
| ATTRIBUTE | DESCRIPTION |
|---|---|
score | Score value between 0.0 and 1.0 (required). TYPE: |
feedback | Human-readable feedback text (required). TYPE: |
Examples:
Simple critic output:
Using with LlmAgent:
from google.adk.agents import LlmAgent
from gepa_adk.adapters.critic_scorer import SimpleCriticOutput
critic = LlmAgent(
name="simple_critic",
model="gemini-2.5-flash",
instruction=SIMPLE_CRITIC_INSTRUCTION,
output_schema=SimpleCriticOutput,
)
Note
Applies to basic evaluation tasks where only a score and feedback are needed. For more detailed evaluations with dimension scores, use CriticOutput instead.
See Also
CriticOutput: Advanced schema with dimension scores and guidance.
Source code in src/gepa_adk/adapters/critic_scorer.py
CriticOutput ¶
Bases: BaseModel
flowchart TD
gepa_adk.adapters.critic_scorer.CriticOutput[CriticOutput]
click gepa_adk.adapters.critic_scorer.CriticOutput href "" "gepa_adk.adapters.critic_scorer.CriticOutput"
Advanced schema for structured critic feedback with dimensions.
This schema defines the expected JSON structure that critic agents should return when configured with output_schema. The score field is required, while other fields are optional and will be preserved in metadata.
| ATTRIBUTE | DESCRIPTION |
|---|---|
score | Score value between 0.0 and 1.0 (required). TYPE: |
feedback | Human-readable feedback text (optional). TYPE: |
dimension_scores | Per-dimension evaluation scores (optional). TYPE: |
actionable_guidance | Specific improvement suggestions (optional). TYPE: |
Examples:
Advanced critic output:
{
"score": 0.75,
"feedback": "Good response but could be more concise",
"dimension_scores": {
"accuracy": 0.9,
"clarity": 0.6,
"completeness": 0.8
},
"actionable_guidance": "Reduce response length by 30%"
}
Note
All critic agents using this schema must return structured JSON. When this schema is used as output_schema on an LlmAgent, the agent can ONLY reply and CANNOT use any tools. This is acceptable for critic agents focused on scoring.
See Also
SimpleCriticOutput: KISS schema with just score + feedback.
Source code in src/gepa_adk/adapters/critic_scorer.py
CriticScorer ¶
Adapter that wraps ADK critic agents to provide structured scoring.
CriticScorer implements the Scorer protocol, enabling integration with gepa-adk's evaluation and evolution workflows. It executes ADK critic agents (LlmAgent, SequentialAgent, etc.) and extracts structured scores with metadata from their outputs.
| ATTRIBUTE | DESCRIPTION |
|---|---|
critic_agent | ADK agent configured for evaluation. TYPE: |
_session_service | Session service for state management. TYPE: |
_app_name | Application name for session identification. TYPE: |
_logger | Bound logger with scorer context. TYPE: |
Examples:
Basic usage:
from google.adk.agents import LlmAgent
from gepa_adk.adapters.critic_scorer import CriticScorer, CriticOutput
from gepa_adk.adapters.agent_executor import AgentExecutor
critic = LlmAgent(
name="quality_critic",
model="gemini-2.5-flash",
instruction="Evaluate response quality...",
output_schema=CriticOutput,
)
executor = AgentExecutor()
scorer = CriticScorer(critic_agent=critic, executor=executor)
score, metadata = await scorer.async_score(
input_text="What is Python?",
output="Python is a programming language.",
)
Note
Adapter wraps ADK critic agents to provide structured scoring. Implements Scorer protocol for compatibility with evolution engine. Creates isolated sessions per scoring call unless session_id provided.
Source code in src/gepa_adk/adapters/critic_scorer.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 | |
__init__ ¶
__init__(
critic_agent: BaseAgent,
executor: AgentExecutorProtocol,
session_service: BaseSessionService | None = None,
app_name: str = "critic_scorer",
) -> None
Initialize CriticScorer with critic agent.
| PARAMETER | DESCRIPTION |
|---|---|
critic_agent | ADK agent (LlmAgent or workflow agent) configured for evaluation. TYPE: |
executor | AgentExecutorProtocol implementation for unified agent execution. Handles session management and execution, enabling feature parity across all agent types. TYPE: |
session_service | Optional session service for state management. If None, creates an InMemorySessionService. TYPE: |
app_name | Application name for session identification. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
TypeError | If critic_agent is not a BaseAgent instance. |
ValueError | If app_name is empty string. |
Examples:
Basic setup with executor:
from gepa_adk.adapters.agent_executor import AgentExecutor
executor = AgentExecutor()
scorer = CriticScorer(critic_agent=critic, executor=executor)
With shared session service:
from google.adk.sessions import InMemorySessionService
from gepa_adk.adapters.agent_executor import AgentExecutor
session_service = InMemorySessionService()
executor = AgentExecutor(session_service=session_service)
scorer = CriticScorer(
critic_agent=critic,
executor=executor,
session_service=session_service,
)
Note
Creates logger with scorer context and validates agent type.
Source code in src/gepa_adk/adapters/critic_scorer.py
async_score async ¶
async_score(
input_text: str,
output: str,
expected: str | None = None,
session_id: str | None = None,
) -> tuple[float, dict[str, Any]]
Score an agent output asynchronously using the critic agent.
Executes the critic agent with formatted input and extracts structured score and metadata from the response.
| PARAMETER | DESCRIPTION |
|---|---|
input_text | The original input provided to the agent being evaluated. TYPE: |
output | The agent's generated output to score. TYPE: |
expected | Optional expected/reference output for comparison. TYPE: |
session_id | Optional session ID to share state with main agent workflow. If None, creates an isolated session. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
float | Tuple of (score, metadata) where: |
dict[str, Any] |
|
tuple[float, dict[str, Any]] |
|
| RAISES | DESCRIPTION |
|---|---|
CriticOutputParseError | If critic output is not valid JSON. |
MissingScoreFieldError | If score field missing from output. |
Examples:
Basic async scoring:
score, metadata = await scorer.async_score(
input_text="What is Python?",
output="Python is a programming language.",
)
With session sharing:
score, metadata = await scorer.async_score(
input_text="...",
output="...",
session_id="existing_session_123",
)
Note
Orchestrates critic agent execution via AgentExecutor and extracts structured output. Creates isolated session unless session_id provided for state sharing.
Source code in src/gepa_adk/adapters/critic_scorer.py
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 | |
score ¶
Score an agent output synchronously using the critic agent.
Synchronous wrapper around async_score() using asyncio.run().
| PARAMETER | DESCRIPTION |
|---|---|
input_text | The original input provided to the agent being evaluated. TYPE: |
output | The agent's generated output to score. TYPE: |
expected | Optional expected/reference output for comparison. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
float | Tuple of (score, metadata) where: |
dict[str, Any] |
|
tuple[float, dict[str, Any]] |
|
| RAISES | DESCRIPTION |
|---|---|
CriticOutputParseError | If critic output is not valid JSON. |
MissingScoreFieldError | If score field missing from output. |
Examples:
Basic sync scoring:
Note
Operates synchronously by wrapping async_score() with asyncio.run(). Uses asyncio.run() to execute async_score(). Prefer async_score() for better performance in async contexts.
Source code in src/gepa_adk/adapters/critic_scorer.py
normalize_feedback ¶
Normalize critic feedback to consistent trial format.
Converts both simple and advanced critic outputs to a standardized format for use in trial records. This enables the reflection agent to receive consistent feedback regardless of which critic schema was used.
| PARAMETER | DESCRIPTION |
|---|---|
score | The numeric score from the critic (0.0-1.0). TYPE: |
metadata | Optional metadata dict from critic output. May contain: - feedback (str): Simple feedback text - dimension_scores (dict): Per-dimension scores - actionable_guidance (str): Improvement suggestions - Any additional fields from critic output TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any] | Normalized feedback dict with structure: |
dict[str, Any] | ```python |
dict[str, Any] | { "score": 0.75, "feedback_text": "Main feedback message", "dimension_scores": {...}, # Optional "actionable_guidance": "...", # Optional |
dict[str, Any] | } |
dict[str, Any] | ``` |
Examples:
Normalize simple feedback:
normalized = normalize_feedback(0.8, {"feedback": "Good job"})
# {"score": 0.8, "feedback_text": "Good job"}
Normalize advanced feedback:
normalized = normalize_feedback(
0.6,
{
"feedback": "Needs work",
"dimension_scores": {"clarity": 0.5},
"actionable_guidance": "Add examples",
},
)
# {
# "score": 0.6,
# "feedback_text": "Needs work",
# "dimension_scores": {"clarity": 0.5},
# "actionable_guidance": "Add examples",
# }
Handle missing feedback:
Note
Supports both SimpleCriticOutput and CriticOutput schemas for flexible critic integration. Extracts the "feedback" field and renames it to "feedback_text" for consistent trial structure. Additional fields like dimension_scores are preserved when present.
Source code in src/gepa_adk/adapters/critic_scorer.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |