Skip to content

Commit

Permalink
reflexion cot/react math strat skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
alckasoc committed Jun 23, 2024
1 parent a6b6d41 commit c36d52d
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions agential/cog/strategies/reflexion/math.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Reflexion Agent strategies for Math."""

from typing import Any, Dict, List, Tuple
from langchain_core.language_models.chat_models import BaseChatModel
from agential.cog.strategies.reflexion.base import (

Check warning on line 5 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L3-L5

Added lines #L3 - L5 were not covered by tests
ReflexionCoTBaseStrategy,
ReflexionReActBaseStrategy,
)


class ReflexionCoTMathStrategy(ReflexionCoTBaseStrategy):
def __init__(self, llm: BaseChatModel) -> None:
super().__init__(llm)

Check warning on line 13 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L11-L13

Added lines #L11 - L13 were not covered by tests

def generate(self, *args: Any, **kwargs: Any) -> str:
return super().generate(*args, **kwargs)

Check warning on line 16 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L15-L16

Added lines #L15 - L16 were not covered by tests

def generate_action(self, question: str, examples: str, reflections: str, prompt: str, additional_keys: Dict[str, str]) -> Tuple[str, str]:
return super().generate_action(question, examples, reflections, prompt, additional_keys)

Check warning on line 19 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L18-L19

Added lines #L18 - L19 were not covered by tests

def generate_observation(self, action_type: str, query: str, key: str) -> Tuple[bool | str]:
return super().generate_observation(action_type, query, key)

Check warning on line 22 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L21-L22

Added lines #L21 - L22 were not covered by tests

def create_output_dict(self, thought: str, action_type: str, obs: str, is_correct: bool, reflections: List[str]) -> Dict[str, Any]:
return super().create_output_dict(thought, action_type, obs, is_correct, reflections)

Check warning on line 25 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L24-L25

Added lines #L24 - L25 were not covered by tests

def halting_condition(self, idx: int, key: str, **kwargs: Any) -> bool:
return super().halting_condition(idx, key, **kwargs)

Check warning on line 28 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L27-L28

Added lines #L27 - L28 were not covered by tests

def reset(self, *args: Any, **kwargs: Any) -> None:
return super().reset(*args, **kwargs)

Check warning on line 31 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L30-L31

Added lines #L30 - L31 were not covered by tests

def reflect(self, reflect_strategy: str, question: str, examples: str, prompt: str, additional_keys: Dict[str, str]) -> Tuple[List[str] | str]:
return super().reflect(reflect_strategy, question, examples, prompt, additional_keys)

Check warning on line 34 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L33-L34

Added lines #L33 - L34 were not covered by tests

def reflect_condition(self, idx: int, reflect_strategy: str | None, key: str) -> bool:
return super().reflect_condition(idx, reflect_strategy, key)

Check warning on line 37 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L36-L37

Added lines #L36 - L37 were not covered by tests


class ReflexionReActMathStrategy(ReflexionReActBaseStrategy):
def __init__(self, llm: BaseChatModel) -> None:
super().__init__(llm)

Check warning on line 42 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L40-L42

Added lines #L40 - L42 were not covered by tests

def generate(self, *args: Any, **kwargs: Any) -> str:
return super().generate(*args, **kwargs)

Check warning on line 45 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L44-L45

Added lines #L44 - L45 were not covered by tests

def generate_action(self, question: str, examples: str, reflections: str, prompt: str, additional_keys: Dict[str, str], **kwargs: Any) -> Tuple[str]:
return super().generate_action(question, examples, reflections, prompt, additional_keys, **kwargs)

Check warning on line 48 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L47-L48

Added lines #L47 - L48 were not covered by tests

def generate_observation(self, step_idx: int, action_type: str, query: str, key: str) -> Tuple[bool | str]:
return super().generate_observation(step_idx, action_type, query, key)

Check warning on line 51 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L50-L51

Added lines #L50 - L51 were not covered by tests

def create_output_dict(self, react_out: List[Dict[str, Any]], reflections: List[str]) -> Dict[str, Any]:
return super().create_output_dict(react_out, reflections)

Check warning on line 54 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L53-L54

Added lines #L53 - L54 were not covered by tests

def react_create_output_dict(self, thought: str, action_type: str, query: str, obs: str, is_correct: bool) -> Dict[str, str]:
return super().react_create_output_dict(thought, action_type, query, obs, is_correct)

Check warning on line 57 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L56-L57

Added lines #L56 - L57 were not covered by tests

def halting_condition(self, idx: int, key: str, **kwargs: Any) -> bool:
return super().halting_condition(idx, key, **kwargs)

Check warning on line 60 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L59-L60

Added lines #L59 - L60 were not covered by tests

def react_halting_condition(self, step_idx: int, question: str, examples: str, reflections: str, prompt: str, additional_keys: Dict[str, str], **kwargs: Any) -> bool:
return super().react_halting_condition(step_idx, question, examples, reflections, prompt, additional_keys, **kwargs)

Check warning on line 63 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L62-L63

Added lines #L62 - L63 were not covered by tests

def reset(self, *args: Any, **kwargs: Any) -> None:
return super().reset(*args, **kwargs)

Check warning on line 66 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L65-L66

Added lines #L65 - L66 were not covered by tests

def reflect(self, reflect_strategy: str, question: str, examples: str, prompt: str, additional_keys: Dict[str, str]) -> Tuple[List[str] | str]:
return super().reflect(reflect_strategy, question, examples, prompt, additional_keys)

Check warning on line 69 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L68-L69

Added lines #L68 - L69 were not covered by tests

def reflect_condition(self, step_idx: int, reflect_strategy: str | None, question: str, examples: str, key: str, prompt: str, additional_keys: Dict[str, str], **kwargs: Dict[str, str]) -> bool:
return super().reflect_condition(step_idx, reflect_strategy, question, examples, key, prompt, additional_keys, **kwargs)

Check warning on line 72 in agential/cog/strategies/reflexion/math.py

View check run for this annotation

Codecov / codecov/patch

agential/cog/strategies/reflexion/math.py#L71-L72

Added lines #L71 - L72 were not covered by tests

0 comments on commit c36d52d

Please sign in to comment.