Skip to content

Commit 56961da

Browse files
authored
Merge pull request #8 from UiPath/sample/quickstart_agent
Sample/quickstart agent
2 parents 3a105d3 + fe3d32c commit 56961da

9 files changed

Lines changed: 2809 additions & 53 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,8 @@ cython_debug/
172172

173173
# PyPI configuration file
174174
.pypirc
175+
176+
**/uipath.db
177+
**/.uipath
178+
**/**.nupkg
179+
**/__uipath/

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-llamaindex"
3-
version = "0.0.4"
3+
version = "0.0.5"
44
description = "UiPath LlamaIndex SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": ["."],
33
"workflows": {
4-
"agentic_w": "main.py:agent"
4+
"agent": "main.py:agent"
55
},
66
"env": ".env"
77
}

samples/quickstart-agent/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from llama_index.llms.openai import OpenAI
99

1010

11+
class TopicEvent(StartEvent):
12+
topic: str
13+
14+
1115
class JokeEvent(Event):
1216
joke: str
1317

@@ -16,7 +20,7 @@ class JokeFlow(Workflow):
1620
llm = OpenAI()
1721

1822
@step
19-
async def generate_joke(self, ev: StartEvent) -> JokeEvent:
23+
async def generate_joke(self, ev: TopicEvent) -> JokeEvent:
2024
topic = ev.topic
2125

2226
prompt = f"Write your best joke about {topic}."

samples/quickstart-agent/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
2-
name = "llama-demo"
3-
version = "0.0.1"
4-
description = "UiPath LlamaIndex SDK"
2+
name = "llama-quickstart-agent"
3+
version = "0.0.2"
4+
description = "UiPath LlamaIndex Quickstart Agent"
55
authors = [{ name = "John Doe", email = "john.doe@myemail.com" }]
66
readme = { file = "README.md", content-type = "text/markdown" }
77
requires-python = ">=3.10"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"entryPoints": [
3+
{
4+
"filePath": "agent",
5+
"uniqueId": "f646d823-434c-4ef6-b8fb-6a239ee08974",
6+
"type": "agent",
7+
"input": {
8+
"type": "object",
9+
"properties": {
10+
"topic": {
11+
"title": "Topic",
12+
"type": "string"
13+
}
14+
},
15+
"required": [
16+
"topic"
17+
]
18+
},
19+
"output": {
20+
"type": "object",
21+
"properties": {},
22+
"required": []
23+
}
24+
}
25+
],
26+
"bindings": {
27+
"version": "2.0",
28+
"resources": []
29+
}
30+
}

samples/quickstart-agent/uv.lock

Lines changed: 2757 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uipath_llamaindex/_cli/_runtime/_runtime.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import logging
33
from typing import Optional
44

5-
from llama_index.core.workflow import StartEvent
65
from uipath import UiPath
76
from uipath._cli._runtime._contracts import (
87
UiPathBaseRuntime,
@@ -40,7 +39,9 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
4039
await self.validate()
4140

4241
try:
43-
ev = StartEvent(**self.context.input_json)
42+
start_event_class = self.context.workflow._start_event_class
43+
44+
ev = start_event_class(**self.context.input_json)
4445

4546
handler = self.context.workflow.run(start_event=ev)
4647

src/uipath_llamaindex/_cli/cli_init.py

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import asyncio
2-
import inspect
32
import json
43
import os
54
import uuid
6-
from typing import Any, Dict, Optional, Type, get_type_hints
5+
from typing import Any, Dict
76

8-
from llama_index.core.workflow import Event, StartEvent, StopEvent, Workflow
9-
from llama_index.core.workflow.decorators import StepConfig
7+
from llama_index.core.workflow import StopEvent, Workflow
108
from uipath._cli._utils._console import ConsoleLogger
119
from uipath._cli._utils._parse_ast import generate_bindings_json # type: ignore
1210
from uipath._cli.middlewares import MiddlewareResult
@@ -50,45 +48,6 @@ def process_nullable_types(properties: Dict[str, Any]) -> Dict[str, Any]:
5048
return result
5149

5250

53-
def find_event_types(workflow: Workflow, event_base_class: Type[Event]) -> Type[Event]:
54-
"""Find the StartEvent or StopEvent class in a workflow"""
55-
event_classes = set()
56-
57-
# Get all steps from the workflow
58-
steps = {}
59-
60-
# Get steps defined as methods
61-
for name, method in inspect.getmembers(workflow, inspect.ismethod):
62-
if hasattr(method, "__step_config"):
63-
steps[name] = method
64-
65-
# Get steps defined as free functions
66-
class_steps = getattr(workflow.__class__, "_step_functions", {})
67-
steps.update(class_steps)
68-
69-
# Find all event types that are subclasses of event_base_class
70-
for step_func in steps.values():
71-
step_config: Optional[StepConfig] = getattr(step_func, "__step_config")
72-
73-
if event_base_class is StartEvent:
74-
# Look in accepted_events for StartEvent
75-
for event_type in step_config.accepted_events:
76-
if issubclass(event_type, event_base_class):
77-
event_classes.add(event_type)
78-
else:
79-
# Look in return_types for StopEvent
80-
for event_type in step_config.return_types:
81-
if issubclass(event_type, event_base_class):
82-
event_classes.add(event_type)
83-
84-
if len(event_classes) == 1:
85-
return event_classes.pop()
86-
elif len(event_classes) > 1:
87-
# Return the most specific one (the one with the most fields)
88-
return max(event_classes, key=lambda cls: len(get_type_hints(cls)))
89-
return event_base_class # Default fallback
90-
91-
9251
def generate_schema_from_workflow(workflow: Workflow) -> Dict[str, Any]:
9352
"""Extract input/output schema from a LlamaIndex workflow"""
9453
schema = {
@@ -97,8 +56,8 @@ def generate_schema_from_workflow(workflow: Workflow) -> Dict[str, Any]:
9756
}
9857

9958
# Find the actual StartEvent and StopEvent classes used in this workflow
100-
start_event_class = find_event_types(workflow, StartEvent)
101-
stop_event_class = find_event_types(workflow, StopEvent)
59+
start_event_class = workflow._start_event_class
60+
stop_event_class = workflow._stop_event_class
10261

10362
# Generate input schema from StartEvent using Pydantic's schema method
10463
try:

0 commit comments

Comments
 (0)