MCPcopy
hub / github.com/langroid/langroid / test_task_cost

Function test_task_cost

tests/main/test_task.py:35–63  ·  view source on GitHub ↗

Test that max_cost, max_tokens are respected by Task.run()

(test_settings: Settings)

Source from the content-addressed store, hash-verified

33
34
35def test_task_cost(test_settings: Settings):
36 """Test that max_cost, max_tokens are respected by Task.run()"""
37
38 set_global(test_settings)
39 settings.cache = False
40 agent = ChatAgent(ChatAgentConfig(name="Test"))
41 agent.llm.reset_usage_cost()
42 task = Task(
43 agent,
44 interactive=False,
45 single_round=False,
46 system_message="User will send you a number. Repeat the number.",
47 )
48 sub_agent = ChatAgent(ChatAgentConfig(name="Sub"))
49 sub_agent.llm.reset_usage_cost()
50 sub = Task(
51 sub_agent,
52 interactive=False,
53 single_round=True,
54 system_message="User will send you a number. Return its double",
55 )
56 task.add_sub_task(sub)
57 response = task.run("4", turns=10, max_cost=0.0005, max_tokens=100)
58 settings.cache = True
59 assert response is not None
60 assert response.metadata.status in [
61 lr.StatusCode.MAX_COST,
62 lr.StatusCode.MAX_TOKENS,
63 ]
64
65
66@pytest.mark.parametrize("restart", [True, False])

Callers

nothing calls this directly

Calls 7

add_sub_taskMethod · 0.95
runMethod · 0.95
set_globalFunction · 0.90
ChatAgentClass · 0.90
ChatAgentConfigClass · 0.90
TaskClass · 0.90
reset_usage_costMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…