Useful Pluginsre_act

re_act

ReAct (Reason + Act) pattern for intelligent agents

What it does

The re_act plugin implements the ReAct pattern:

Plan (after_user_input)

Before taking any action, the agent plans what to do based on user input and available tools.

Reflect (after_tools)

After each tool execution, the agent reflects on results and decides next steps.

Quick Start

main.py
from connectonion import Agent from connectonion.useful_plugins import re_act def search(query: str) -> str: """Search the web for information.""" return f"Results for '{query}': Python is a programming language..." agent = Agent("assistant", tools=[search], plugins=[re_act]) agent.input("Search for Python and explain what it is")
output
๐Ÿ’ญ I'll search for information about Python, then explain what it is based on the results.
[Tool: search("Python")]
๐Ÿ’ญ The search returned that Python is a programming language. I now have enough context to explain.
Python is a high-level, interpreted programming language known for its simplicity...

Want to customize? Run co copy re_act to get an editable copy.

How it works

1. Planning Phase

After receiving user input, the plugin generates a brief plan:

main.py
# Internal: plan_task handler @after_user_input def plan_task(agent): user_prompt = agent.current_session.get('user_prompt', '') tool_names = agent.tools.names() plan = llm_do( f"User request: {user_prompt}\nAvailable tools: {tool_names}\nBrief plan:", model="co/gemini-2.5-flash" ) agent.current_session['messages'].append({ 'role': 'assistant', 'content': f"๐Ÿ’ญ {plan}" })

2. Reflection Phase

After tools execute, the plugin reflects on results:

main.py
# Uses the built-in reflect handler from useful_events_handlers @after_tools def reflect(agent): trace = agent.current_session['trace'][-1] if trace['type'] == 'tool_execution' and trace['status'] == 'success': reflection = llm_do( f"Result: {trace['result'][:200]}\nWhat did we learn?", model="co/gemini-2.5-flash" ) agent.current_session['messages'].append({ 'role': 'assistant', 'content': f"๐Ÿ’ญ {reflection}" })

Combined with Eval Plugin

For debugging and testing, combine with the eval plugin:

main.py
from connectonion import Agent from connectonion.useful_plugins import re_act, eval # ReAct provides planning, eval provides evaluation at completion agent = Agent("assistant", tools=[search], plugins=[re_act, eval]) agent.input("Search for Python") # Output includes: # ๐Ÿ’ญ Plan: I'll search for Python information # [Tool execution] # ๐Ÿ’ญ Reflection: We learned Python is a programming language # โœ“ Evaluation: Task complete - found and understood Python info

Events Used

EventHandlerPurpose
after_user_inputplan_taskGenerate initial plan
after_toolsreflectReflect on tool results

Source

connectonion/useful_plugins/re_act.py

main.py
# The plugin is just a list of event handlers re_act = [plan_task, reflect]

Star us on GitHub

If ConnectOnion saves you time, a โญ goes a long way โ€” and earns you a coffee chat with our founder.