Test that max_cost, max_tokens are respected by Task.run()
(test_settings: Settings)
| 33 | |
| 34 | |
| 35 | def 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]) |
nothing calls this directly
no test coverage detected
searching dependent graphs…