Skip to content

Learning

The learn capability is what makes A2E agents self-improving. It defines a standard protocol for feedback (human, environment, or self-critique), experience replay (on-policy and off-policy), and adaptation (UCB1, epsilon-greedy, softmax, or custom strategies). Every agent action becomes a training signal; every correction becomes a policy improvement.

Overview

The learn capability provides a feedback-driven learning system — agents can submit feedback signals, record RL experience, trigger component adaptation, and query performance statistics. It bridges agent evaluation with policy optimization.

Protocol Messages (18 types)

Type StringModelDirection
learn/feedback/reqLearnFeedbackRequestAgent → Host
learn/feedback/respLearnFeedbackResponseHost → Agent
learn/experience/reqLearnExperienceRequestAgent → Host
learn/experience/respLearnExperienceResponseHost → Agent
learn/adapt/reqLearnAdaptRequestAgent → Host
learn/adapt/respLearnAdaptResponseHost → Agent
learn/stats/reqLearnStatsRequestAgent → Host
learn/stats/respLearnStatsResponseHost → Agent
learn/refinement/plan/reqLearnRefinementPlanRequestAgent → Host
learn/refinement/plan/respLearnRefinementPlanResponseHost → Agent
learn/refinement/apply/reqLearnRefinementApplyRequestAgent → Host
learn/refinement/apply/respLearnRefinementApplyResponseHost → Agent
learn/refinement/rollback/reqLearnRefinementRollbackRequestAgent → Host
learn/refinement/rollback/respLearnRefinementRollbackResponseHost → Agent
learn/refinement/review/reqLearnRefinementReviewRequestAgent → Host
learn/refinement/review/respLearnRefinementReviewResponseHost → Agent
learn/refinement/history/reqLearnRefinementHistoryRequestAgent → Host
learn/refinement/history/respLearnRefinementHistoryResponseHost → Agent

Feedback Model

FeedbackPolarity: POSITIVE, NEGATIVE, NEUTRAL, CORRECTIVE

FeedbackDimension: CORRECTNESS, HELPFULNESS, SAFETY, TONE, PLAN_QUALITY

FeedbackSource: HUMAN, ENV, SELF

FieldTypeDescription
correlation_idstrLinks to the original request
polarityFeedbackPolarityPositive/negative/neutral/corrective
scorefloat-1.0 to +1.0
dimensionFeedbackDimensionWhat aspect is being evaluated
confidencefloat0-1 confidence in this feedback
commentstrFree-text explanation
correctionstrCorrected output (for CORRECTIVE polarity)
correction_spandictPosition of the correction
sourceFeedbackSourceWho gave the feedback
annotator_idstrAnnotator identifier
rated_turnRatedTurnAssociated prompt/response pair

Validation: CORRECTIVE polarity requires correction text (enforced by Pydantic @model_validator).

Conversion methods:

  • to_preference_pair() → DPO training pair (chosen vs rejected)
  • to_reward_sample() → Reward model training sample

Experience Model (RL Replay)

python
Experience(
    state: dict,        # Current state
    action: dict,       # Action taken (keyed by component_name)
    reward: float,      # Reward received
    next_state: dict,   # Resulting state
    done: bool          # Terminal flag
)

ComponentPerformanceRecord

Rolling per-component performance stats (replaces SkillPerformanceRecord):

FieldTypeDescription
component_namestrComponent identifier (skill, tool, subagent, toolkit)
calls_totalintTotal invocations
calls_successintSuccessful calls
calls_failedintFailed calls
avg_duration_msfloatAverage execution time
avg_scorefloatAverage feedback score
p95_duration_msfloatP95 latency

Adaptation Strategies

StrategyDescription
ucb1Upper Confidence Bound — explore/exploit based on confidence intervals
epsilon_greedyRandom exploration with epsilon probability
softmaxBoltzmann exploration over value estimates
customUser-defined strategy

LearnPlugin ABC

python
class LearnPlugin(A2EPlugin):
    name = "learn"
    priority = 5

    @abstractmethod
    def _record_feedback(self, feedbacks) -> tuple[int, dict]: ...

    @abstractmethod
    def _store_experiences(self, experiences) -> int: ...

    @abstractmethod
    def _adapt(self, component_name, strategy) -> list[ComponentPerformanceRecord]: ...

    @abstractmethod
    def _get_stats(self, component_name, tool_name) -> dict: ...

LearnAPI (Client)

python
from a2e.caps.learn.client import LearnAPI

learn = LearnAPI(client)

# Submit feedback
resp = learn.feedback(
    polarity="POSITIVE",
    score=0.9,
    dimension="CORRECTNESS",
    confidence=0.95,
    prompt="What is 2+2?",
    response="4",
    source="HUMAN",
    comment="Correct answer"
)

# Record RL experience
count = learn.experience([
    {"state": {"count": 0}, "action": {"component_name": "inc"}, "reward": 1.0,
     "next_state": {"count": 1}, "done": False}
])

# Fire-and-forget adaptation (server handles plan → review → apply → stats)
records = learn.adapt(component_name="", strategy="ppo")

# Unified refinement interface — one method, five modes
plan = learn.refine(component_name="my-tool", action="plan")
review = learn.refine(component_name="my-tool", action="review", proposal=plan["proposals"][0])
result = learn.refine(component_name="my-tool", action="apply", proposal=plan["proposals"][0])
result = learn.refine(component_name="my-tool", action="rollback", refinement_id="ref-123")
history = learn.refine(component_name="my-tool", action="history")

# Query stats
records = learn.stats(component_name="my-tool")

# Convenience: send scalar reward
learn.reward(component_name="my-tool", value=1.0, correlation_id="req_123")

adapt() vs refine() — When to Use Which

Aspectadapt()refine(action=...)
GranularityBatch — plans, reviews, and applies all proposals in one callPer-proposal — plan, review, apply, rollback individually
Control flowFire-and-forgetStep-by-step with decision points
Per-proposal inspectionNo — applies all approved proposals automaticallyYes — you decide accept/reject per proposal
RollbackNo — once applied, changes are permanentYes — action="rollback" undoes a bad apply
HistoryNo — no way to query past refinementsYes — action="history" loads the full refinement log
Best forSimple auto-optimization with no human oversightHuman-in-the-loop, safety-critical, or auditable workflows

Rule of thumb

  • adapt() = "optimize everything, I trust the system"
  • refine(action="plan") = "show me the proposals"
  • refine(action="review") = "let me gate each proposal"
  • refine(action="apply") = "apply this specific proposal"
  • refine(action="rollback") = "undo the last apply"
  • refine(action="history") = "show me what changed"

See also

  • Learning protocol messages — the full request/response reference for the learn capability, including fields, directions, and wire examples
  • Environment capability — how agent actions are scored and turned into rewards that feed the learn experience buffer
  • Protocol: Learning — the wire-level message definitions for learn/feedback, learn/experience, and learn/adapt

The learn capability is the feedback engine behind A2E's self-improvement loop: environment or human feedback is recorded as experience, then adapt() or refine() turns that experience into policy updates you can gate, apply, and roll back.

A2E Protocol v1.0 — Released under the MIT License.