MCPcopy Index your code
hub / github.com/langroid/langroid / Task

Class Task

langroid/agent/task.py:175–2499  ·  view source on GitHub ↗

A `Task` wraps an `Agent` object, and sets up the `Agent`'s goals and instructions. A `Task` maintains two key variables: - `self.pending_message`, which is the message awaiting a response, and - `self.pending_sender`, which is the entity that sent the pending message. The pos

Source from the content-addressed store, hash-verified

173
174
175class Task:
176 """
177 A `Task` wraps an `Agent` object, and sets up the `Agent`'s goals and instructions.
178 A `Task` maintains two key variables:
179
180 - `self.pending_message`, which is the message awaiting a response, and
181 - `self.pending_sender`, which is the entity that sent the pending message.
182
183 The possible responders to `self.pending_message` are the `Agent`'s own "native"
184 responders (`agent_response`, `llm_response`, and `user_response`), and
185 the `run()` methods of any sub-tasks. All responders have the same type-signature
186 (somewhat simplified):
187 ```
188 str | ChatDocument -> ChatDocument
189 ```
190 Responders may or may not specify an intended recipient of their generated response.
191
192 The main top-level method in the `Task` class is `run()`, which repeatedly calls
193 `step()` until `done()` returns true. The `step()` represents a "turn" in the
194 conversation: this method sequentially (in round-robin fashion) calls the responders
195 until it finds one that generates a *valid* response to the `pending_message`
196 (as determined by the `valid()` method). Once a valid response is found,
197 `step()` updates the `pending_message` and `pending_sender` variables,
198 and on the next iteration, `step()` re-starts its search for a valid response
199 *from the beginning* of the list of responders (the exception being that the
200 human user always gets a chance to respond after each non-human valid response).
201 This process repeats until `done()` returns true, at which point `run()` returns
202 the value of `result()`, which is the final result of the task.
203 """
204
205 # class variable called `cache` that is a RedisCache object
206 _cache: RedisCache | None = None
207 _background_tasks_started: bool = False
208
209 def __init__(
210 self,
211 agent: Optional[Agent] = None,
212 name: str = "",
213 llm_delegate: bool = False,
214 single_round: bool = False,
215 system_message: str = "",
216 user_message: str | None = "",
217 restart: bool = True,
218 default_human_response: Optional[str] = None,
219 interactive: bool = True,
220 only_user_quits_root: bool = True,
221 erase_substeps: bool = False,
222 allow_null_result: bool = False,
223 max_stalled_steps: int = 5,
224 default_return_type: Optional[type] = None,
225 done_if_no_response: List[Responder] = [],
226 done_if_response: List[Responder] = [],
227 config: TaskConfig = TaskConfig(),
228 **kwargs: Any, # catch-all for any legacy params, for backwards compatibility
229 ):
230 """
231 A task to be performed by an agent.
232

Callers 15

_set_up_taskMethod · 0.90
get_verbatim_extractsMethod · 0.90
newMethod · 0.90
_test_table_chat_agentFunction · 0.90
test_addressingFunction · 0.90
test_doc_chat_agent_taskFunction · 0.90
test_retrieval_toolFunction · 0.90
test_doc_chat_followupFunction · 0.90

Calls

no outgoing calls

Tested by 15

_test_table_chat_agentFunction · 0.72
test_addressingFunction · 0.72
test_doc_chat_agent_taskFunction · 0.72
test_retrieval_toolFunction · 0.72
test_doc_chat_followupFunction · 0.72
test_doc_chat_batchFunction · 0.72
gen_taskFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…