Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 4 additions & 71 deletions agents/autonomous_inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import uuid

from repos.data_repo import DataRepo
from agents.react_agent import ReActAgent, ReasoningStep, StepType, AgentState
from governance.approval import get_approval_queue, ApprovalPolicy
from governance.approval import get_approval_queue
from orchestration.autonomous_graph import process_email_with_graph


Expand Down Expand Up @@ -91,14 +90,12 @@ def __init__(
gateway = None,
user_email: str = "kowshik.naidu@contoso.com",
poll_interval: float = 5.0,
use_langgraph: bool = True
):
self.repo = repo or DataRepo()
self.gateway = gateway
self.user_email = user_email
self.poll_interval = poll_interval
self.use_langgraph = use_langgraph


self.state = ProcessorState()
self.event_queue: queue.Queue = queue.Queue()
self._stop_event = threading.Event()
Expand Down Expand Up @@ -211,11 +208,8 @@ def _process_single_email(self, email: Dict[str, Any]) -> None:
))

try:
if self.use_langgraph:
self._process_with_langgraph(email)
else:
self._process_with_react(email)

self._process_with_langgraph(email)

self.state.processed_count += 1

except Exception as e:
Expand Down Expand Up @@ -317,67 +311,6 @@ def _process_with_langgraph(self, email: Dict[str, Any]) -> None:
}
))

def _process_with_react(self, email: Dict[str, Any]) -> None:
"""Process email using ReAct agent"""
email_id = email.get("email_id")

# Create agent
agent = ReActAgent(
repo=self.repo,
gateway=self.gateway,
user_email=self.user_email,
max_iterations=10
)

# Process and emit events
final_state = None
for step in agent.process_email(email):
# Map ReasoningStep to AgentEvent
if step.step_type == StepType.THINK:
event_type = "thinking"
elif step.step_type == StepType.ACT:
event_type = "action"
elif step.step_type == StepType.OBSERVE:
event_type = "observation"
elif step.step_type == StepType.FINISH:
event_type = "completed"
elif step.step_type == StepType.AWAIT_APPROVAL:
event_type = "approval_needed"
else:
event_type = "info"

self._emit_event(AgentEvent(
event_type=event_type,
email_id=email_id,
content=step.content,
metadata={
"tool": step.tool_name,
"iteration": step.iteration,
"result": step.tool_result
}
))

# Handle approval queue
if step.tool_result and step.tool_result.get("requires_approval"):
approval_queue = get_approval_queue()
approval_queue.add_pending_action(
action_type=step.tool_name,
payload=step.tool_params or {},
reason=f"Agent action during email processing",
source_email_id=email_id,
agent_reasoning=step.content
)

# The generator returns the final state
# (Note: In Python, you'd need to catch the return value differently)

# Mark email as processed
self.repo.mark_email_processed(
email_id,
actions_taken=["react_processed"],
category="processed"
)

def process_email_now(self, email_id: str) -> Generator[AgentEvent, None, None]:
"""
Process a specific email immediately (for manual triggering).
Expand Down
Loading
Loading