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
1 change: 1 addition & 0 deletions samples/simple-hitl-agent/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OPENAI_API_KEY=xxx
35 changes: 35 additions & 0 deletions samples/simple-hitl-agent/agent.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
flowchart TD
step__done["_done"]:::stepStyle
step_aggregate_tool_results["aggregate_tool_results"]:::stepStyle
step_call_tool["call_tool"]:::stepStyle
step_init_run["init_run"]:::stepStyle
step_parse_agent_output["parse_agent_output"]:::stepStyle
step_run_agent_step["run_agent_step"]:::stepStyle
step_setup_agent["setup_agent"]:::stepStyle
event_StopEvent([<p>StopEvent</p>]):::stopEventStyle
event_ToolCallResult([<p>ToolCallResult</p>]):::defaultEventStyle
event_AgentInput([<p>AgentInput</p>]):::defaultEventStyle
event_ToolCall([<p>ToolCall</p>]):::defaultEventStyle
event_AgentWorkflowStartEvent([<p>AgentWorkflowStartEvent</p>]):::defaultEventStyle
event_AgentOutput([<p>AgentOutput</p>]):::defaultEventStyle
event_AgentSetup([<p>AgentSetup</p>]):::defaultEventStyle
event_StopEvent --> step__done
step_aggregate_tool_results --> event_AgentInput
step_aggregate_tool_results --> event_StopEvent
event_ToolCallResult --> step_aggregate_tool_results
step_call_tool --> event_ToolCallResult
event_ToolCall --> step_call_tool
step_init_run --> event_AgentInput
event_AgentWorkflowStartEvent --> step_init_run
step_parse_agent_output --> event_StopEvent
step_parse_agent_output --> event_ToolCall
event_AgentOutput --> step_parse_agent_output
step_run_agent_step --> event_AgentOutput
event_AgentSetup --> step_run_agent_step
step_setup_agent --> event_AgentSetup
event_AgentInput --> step_setup_agent
classDef stepStyle fill:#f2f0ff,line-height:1.2
classDef externalStyle fill:#f2f0ff,line-height:1.2
classDef defaultEventStyle fill-opacity:0
classDef stopEventStyle fill:#bfb6fc
classDef inputRequiredStyle fill:#f2f0ff,line-height:1.2
7 changes: 7 additions & 0 deletions samples/simple-hitl-agent/llama_index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": ["."],
"workflows": {
"agent": "main.py:workflow"
},
"env": ".env"
}
40 changes: 40 additions & 0 deletions samples/simple-hitl-agent/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from llama_index.core.agent.workflow import AgentWorkflow
from llama_index.core.workflow import (
Context,
HumanResponseEvent,
InputRequiredEvent,
)
from llama_index.llms.openai import OpenAI

llm = OpenAI(model="gpt-4o-mini")


# a tool that performs a dangerous task
async def dangerous_task(ctx: Context) -> str:
"""A dangerous task that requires human confirmation."""

# emit an event to the external stream to be captured
ctx.write_event_to_stream(
InputRequiredEvent(
prefix="Are you sure you want to proceed? ",
user_name="Laurie",
)
)

# wait until we see a HumanResponseEvent
response = await ctx.wait_for_event(
HumanResponseEvent, requirements={"user_name": "Laurie"}
)

# act on the input from the event
if response.response.strip().lower() == "yes":
return "Dangerous task completed successfully."
else:
return "Dangerous task aborted."


workflow = AgentWorkflow.from_tools_or_functions(
[dangerous_task],
llm=llm,
system_prompt="You are a helpful assistant that can perform dangerous tasks.",
)
11 changes: 11 additions & 0 deletions samples/simple-hitl-agent/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[project]
name = "llama-simple-hitl-agent"
version = "0.0.2"
description = "UiPath LlamaIndex Simple HITL Agent"
authors = [{ name = "John Doe", email = "john.doe@myemail.com" }]
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.10"
dependencies = [
"uipath-llamaindex>=0.0.13",
"llama-index-llms-openai>=0.2.2"
]
Binary file added samples/simple-hitl-agent/state.db
Binary file not shown.
23 changes: 23 additions & 0 deletions samples/simple-hitl-agent/uipath.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"entryPoints": [
{
"filePath": "agent",
"uniqueId": "ca9074cb-d758-483c-a88d-4346b3214fb6",
"type": "agent",
"input": {
"type": "object",
"properties": {},
"required": []
},
"output": {
"type": "object",
"properties": {},
"required": []
}
}
],
"bindings": {
"version": "2.0",
"resources": []
}
}
2,799 changes: 2,799 additions & 0 deletions samples/simple-hitl-agent/uv.lock

Large diffs are not rendered by default.