Useful Pluginsre_act

re_act

ReAct (Reason + Act) pattern for intelligent agents

What it does

The re_act plugin implements the ReAct pattern:

Acknowledge (after_user_input)

Before taking any action, the agent acknowledges the request in 1-2 sentences to show it understood — planning itself is left to the main agent.

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. Acknowledge Phase

After receiving user input, the plugin acknowledges the request (not a plan — just confirms understanding):

main.py
# Internal: acknowledge_request handler @after_user_input def acknowledge_request(agent): user_prompt = agent.current_session.get('user_prompt', '') conversation = _format_conversation(agent.current_session.get('messages', [])) ack = llm_do( f"Conversation so far:\n{conversation}\n\nCurrent user input: {user_prompt}\n\nAcknowledge this request (1-2 sentences):", model="co/gemini-2.5-flash", system_prompt=ACKNOWLEDGE_PROMPT ) agent.current_session['intent'] = ack agent.current_session['messages'].append({ 'role': 'assistant', 'content': ack })

2. Reflection Phase

After each batch of tools executes, the plugin reflects on the most recent result:

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_result': return tool_name = trace['name'] tool_args = trace['args'] if trace['status'] == 'success': reflection = llm_do( f"Action: {tool_name}({tool_args})\nResult: {str(trace['result'])[:300]}\nWhat did we learn? What's next?", model="co/gemini-2.5-flash" ) agent.current_session['messages'].append({ 'role': 'assistant', 'content': 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: # Acknowledge: "I'll search for Python information and explain it to you." # [Tool execution] # Reflection: We learned Python is a programming language # ✓ Evaluation: Task complete - found and understood Python info

Events Used

EventHandlerPurpose
after_user_inputacknowledge_requestAcknowledge what the user is asking for
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 = [acknowledge_request, reflect]

Star us on GitHub

If ConnectOnion saves you time, a ⭐ goes a long way — and earns you a coffee chat with our founder.