Skip to content
Draft
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[project]
name = "uipath-langchain"
version = "0.0.139"
version = "0.0.140"
description = "UiPath Langchain"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.10"
dependencies = [
"uipath>=2.1.76, <2.2.0",
"uipath>=2.1.86, <2.2.0",
"langgraph>=0.5.0, <0.7.0",
"langchain-core>=0.3.34",
"langgraph-checkpoint-sqlite>=2.0.3",
Expand Down
72 changes: 72 additions & 0 deletions samples/calculator-agent/evals/eval-sets/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"fileName": "default.json",
"id": "default-eval-set-id",
"name": "Basic Calculator Evaluation Set",
"batchSize": 10,
"evaluatorRefs": [
"equality",
"llm-as-a-judge"
],
"evaluations": [
{
"id": "test-addition",
"name": "Test Addition",
"inputs": {"a": 1, "b": 1, "operator": "+"},
"expectedOutput": {"result": 2},
"expectedAgentBehavior": "",
"evalSetId": "default-eval-set-id",
"createdAt": "2025-09-04T18:54:58.378Z",
"updatedAt": "2025-09-04T18:55:55.416Z"
},
{
"id": "test-random-addition-using-mockito",
"name": "Test Random Addition Using Mockito",
"inputs": {"a": 1, "b": 1, "operator": "random"},
"expectedOutput": {"result": 2},
"expectedAgentBehavior": "",
"mockingStrategy": {
"type": "mockito",
"behaviors": [
{
"function": "get_random_operator",
"arguments": {
"args": [],
"kwargs": {}
},
"then": [
{
"type": "return",
"value": {"result": "+"}
}
]
}
]
},
"evalSetId": "default-eval-set-id",
"createdAt": "2025-09-04T18:54:58.378Z",
"updatedAt": "2025-09-04T18:55:55.416Z"
},
{
"id": "test-random-addition-using-llm",
"name": "Test Random Addition Using LLM",
"inputs": {"a": 1, "b": 1, "operator": "random"},
"expectedOutput": {"result": 2},
"expectedAgentBehavior": "",
"mockingStrategy": {
"type": "llm",
"prompt": "The random operator is '+'.",
"toolsToSimulate": [{"name": "get_random_operator"}],
"model": {
"model": "gpt-4o-mini-2024-07-18",
"temperature": 0
}
},
"evalSetId": "default-eval-set-id",
"createdAt": "2025-09-04T18:54:58.378Z",
"updatedAt": "2025-09-04T18:55:55.416Z"
}
],
"modelSettings": [],
"createdAt": "2025-09-04T18:54:58.379Z",
"updatedAt": "2025-09-04T18:55:55.416Z"
}
11 changes: 11 additions & 0 deletions samples/calculator-agent/evals/evaluators/equality.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"fileName": "equality.json",
"id": "equality",
"name": "Equality Evaluator",
"description": "An evaluator that judges the agent based on expected output.",
"category": 0,
"type": 1,
"targetOutputKey": "*",
"createdAt": "2025-06-26T17:45:39.651Z",
"updatedAt": "2025-06-26T17:45:39.651Z"
}
13 changes: 13 additions & 0 deletions samples/calculator-agent/evals/evaluators/llm-as-a-judge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"fileName": "llm-as-a-judge.json",
"id": "llm-as-a-judge",
"name": "LLMAsAJudge Evaluator",
"description": "An evaluator that judges the agent based on it's run history and expected behavior",
"category": 3,
"type": 7,
"prompt": "As an expert evaluator, determine how well the agent did on a scale of 0-100. Focus on if the simulation was successful and if the agent behaved according to the expected output accounting for alternative valid expressions, and reasonable variations in language while maintaining high standards for accuracy and completeness. Provide your score with a justification, explaining briefly and concisely why you gave that score.\n----\nUserOrSyntheticInputGivenToAgent:\n{{UserOrSyntheticInput}}\n----\nSimulationInstructions:\n{{SimulationInstructions}}\n----\nExpectedAgentBehavior:\n{{ExpectedAgentBehavior}}\n----\nAgentRunHistory:\n{{AgentRunHistory}}\n",
"targetOutputKey": "*",
"model": "gpt-4.1-2025-04-14",
"createdAt": "2025-08-21T15:12:58.695Z",
"updatedAt": "2025-08-21T15:12:58.695Z"
}
57 changes: 45 additions & 12 deletions samples/calculator-agent/graph.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,78 @@
import random
from enum import Enum

from langgraph.constants import START, END
from langgraph.graph import StateGraph
from pydantic.dataclasses import dataclass
from uipath.tracing import traced
from uipath.eval.mocks import mockable, ExampleCall


class Operator(Enum):
ADD = "+"
SUBTRACT = "-"
MULTIPLY = "*"
DIVIDE = "/"
RANDOM = "random"


@dataclass
class CalculatorInput:
a: float
b: float
operator: Operator


@dataclass
class CalculatorOutput:
result: float

@traced(name="postprocess")
@dataclass
class Wrapper:
result: Operator

GET_RANDOM_OPERATOR_EXAMPLES = [ExampleCall(id="example", input="{}", output="{\"result\": \"*\"}")]

@traced()
@mockable(example_calls=GET_RANDOM_OPERATOR_EXAMPLES)
async def get_random_operator() -> Wrapper:
"""Return a random math operator."""
return Wrapper(result=random.choice([
Operator.ADD,
Operator.SUBTRACT,
Operator.MULTIPLY,
Operator.DIVIDE,
]))


@traced()
async def postprocess(x: float) -> float:
"""
Example of nested traced invocation.
"""
"""Example of nested traced invocation."""
return x

@traced(name="calculate")

@traced()
async def calculate(input: CalculatorInput) -> CalculatorOutput:
result = 0
match input.operator:
case Operator.ADD: result = input.a + input.b
case Operator.SUBTRACT: result = input.a - input.b
case Operator.MULTIPLY: result = input.a * input.b
case Operator.DIVIDE: result = input.a / input.b if input.b != 0 else 0
if input.operator == Operator.RANDOM:
operator = (await get_random_operator()).result
else:
operator = input.operator

match operator:
case Operator.ADD:
result = input.a + input.b
case Operator.SUBTRACT:
result = input.a - input.b
case Operator.MULTIPLY:
result = input.a * input.b
case Operator.DIVIDE:
result = input.a / input.b if input.b != 0 else 0
case _:
raise ValueError(f"Unknown operator: {operator}")

result = await postprocess(result)
return CalculatorOutput(result=result)


builder = StateGraph(state_schema=CalculatorInput, input=CalculatorInput, output=CalculatorOutput)

builder.add_node("calculate", calculate)
Expand Down
4 changes: 2 additions & 2 deletions samples/calculator-agent/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ description = "Calculator Agent"
authors = [{ name = "John Doe", email = "[email protected]" }]
requires-python = ">=3.10"
dependencies = [
"uipath-langchain>=0.0.130",
"uipath>=2.1.54",
"uipath-langchain>=0.0.138",
"uipath>=2.1.86",
]

[project.optional-dependencies]
Expand Down
Loading
Loading