§
    ÚŽ’j‰&  ã                   óž   — d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 dd	l
mZ dd
lmZ ddlmZmZ  G d„ de¦  «        Z G d„ de¦  «        ZdS )zThe task updated tool class.é    )ÚLiteral)Ú	BaseModelÚFieldé   )Ú_TaskToolBaseé   )Ú	ToolChunké   )Ú
AgentState)ÚDeveloperOrientedException)Ú	TextBlockÚToolResultStatec                   ó€  — e Zd ZU dZ ed¬¦  «        Zeed<    edd¬¦  «        Zedz  ed<    edd	¬¦  «        Z	edz  ed
<    edd¬¦  «        Z
ee         dz  ed<    edd¬¦  «        Zed         dz  ed<    edd¬¦  «        Zee         dz  ed<    edd¬¦  «        Zedz  ed<    edd¬¦  «        Zedz  ed<   dS )Ú_TaskUpdateParamszThe params of the update task.zThe task id.)ÚdescriptionÚtask_idNzNew subject for the task)Údefaultr   ÚsubjectzNew description for the taskr   zTask IDs that this task blocksÚ
add_blockszNew status for the task)ÚpendingÚin_progressÚ	completedÚdeletedÚstatuszTask IDs that block this taskÚadd_blocked_byzNew owner for the taskÚownerzEMetadata keys to merge into the task. Set a key to null to delete it.Úmetadata)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚstrÚ__annotations__r   r   r   Úlistr   r   r   r   r   Údict© ó    úPC:\Projects\DSCons\.venv\Lib\site-packages\agentscope\tool\_task\_update_task.pyr   r      s»  € € € € € € Ø(Ð(à�5 ^Ð4Ñ4Ô4€GˆSÐ4Ð4Ñ4Ø˜%ØØ.ðñ ô €GˆS�4‰Zð ð ñ ð $˜eØØ2ðñ ô €K��t‘ð ð ñ ð $) 5ØØ4ð$ñ $ô $€J��S”	˜DÑ ð ð ñ ð ˆuØØ-ðñ ô ð ˆGð	ôð
 	ñð ð ñ ð (- uØØ3ð(ñ (ô (€N�D˜”I Ñ$ð ð ñ ð ˜ØØ,ðñ ô €Eˆ3�‰:ð ð ñ ð "˜EØð*ðñ ô €Hˆd�T‰kð ð ñ ð ð r'   r   c                   ó  — e Zd ZU dZd Zeed<   dZeed<   e 	                    ¦   «         Z
eed<   	 	 	 	 	 	 	 ddeded	edz  dedz  d
ee         dz  ded         dz  dee         dz  dedz  dedz  defd„Zededededdfd„¦   «         ZdS )Ú
TaskUpdatez"The tool to update the agent task.Únameul  Use this tool to update a task in the task list.

## When to Use This Tool

**Mark tasks as resolved:**
- When you have completed the work described in a task
- When a task is no longer needed or has been superseded
- IMPORTANT: Always mark your assigned tasks as resolved when you finish them
- After resolving, call TaskList to find your next task

- ONLY mark a task as completed when you have FULLY accomplished it
- If you encounter errors, blockers, or cannot finish, keep the task as in_progress
- When blocked, create a new task describing what needs to be resolved
- Never mark a task as completed if:
  - Tests are failing
  - Implementation is partial
  - You encountered unresolved errors
  - You couldn't find necessary files or dependencies

**Delete tasks:**
- When a task is no longer relevant or was created in error
- Setting status to `deleted` permanently removes the task

**Update task details:**
- When requirements change or become clearer
- When establishing dependencies between tasks

## Fields You Can Update

- **status**: The task status (see Status Workflow below)
- **subject**: Change the task title (imperative form, e.g., "Run tests")
- **description**: Change the task description
- **owner**: Change the task owner (agent name)
- **metadata**: Merge metadata keys into the task (set a key to null to delete it)
- **add_blocks**: Mark tasks that cannot start until this one completes
- **add_blocked_by**: Mark tasks that must complete before this one can start

## Status Workflow

Status progresses: `pending` â†’ `in_progress` â†’ `completed`

Use `deleted` to permanently remove a task.

## Staleness

Make sure to read a task's latest state using `TaskGet` before updating it.

## Examples

Mark task as in progress when starting work:
```json
{"task_id": "1", "status": "in_progress"}
```

Mark task as completed after finishing work:
```json
{"task_id": "1", "status": "completed"}
```

Delete a task:
```json
{"task_id": "1", "status": "deleted"}
```

Claim a task by setting owner:
```json
{"task_id": "1", "owner": "my-name"}
```

Set up task dependencies:
```json
{"task_id": "2", "add_blocked_by": ["1"]}
```r   Úinput_schemaNÚ_agent_stater   r   r   r   )r   r   r   r   r   r   r   Úreturnc
              ƒ   ó(  ‡‡‡K  — t          |t          ¦  «        st          d| j        › d|› d�¦  «        ‚d}
t	          |j        j        ¦  «        D ]\  }}|j        |k    r|}
Œ|
€.t          t          d|› d�¬¦  «        gt          j        ¬¦  «        S g }|r,|                     d	¦  «         ||j        j        |
         _        |�,|                     d
¦  «         ||j        j        |
         _        d„ |j        j        D ¦   «         Š|rY|j        j        |
         j        Šˆˆfd„|D ¦   «         }|r1|                     d¦  «         |D ]}|                      |||¦  «         Œ|�Y|j        j        |
         j        Šˆˆfd„|D ¦   «         }|r1|                     d¦  «         |D ]}|                      |||¦  «         Œ|rÉ|dk    r—|j        j                             |
¦  «         |j        j        D ]H}||j        v r|j                             |¦  «         ||j        v r|j                             |¦  «         ŒIt          t          d|› d�¬¦  «        g¬¦  «        S |                     d¦  «         ||j        j        |
         _        |�,|                     d¦  «         ||j        j        |
         _        |	rw|                     d¦  «         |	                     ¦   «         D ]M\  }}|€,|j        j        |
         j                             |d¦  «         Œ3||j        j        |
         j        |<   ŒN|rd|› dd                     |¦  «        › d�}nd|› d�}|j        j        |
         j        dk    r|dz  }t          t          |¬¦  «        g¬¦  «        S )zUpdate the agent task.zError: z) requires AgentState to be provided, got z	 instead.Nz TaskNotFoundError: The task (id=z) does not exist.)Útext)ÚcontentÚstater   r   c                 ó   — g | ]	}|j         ‘Œ
S r&   )Úid)Ú.0Ú_s     r(   ú
<listcomp>z#TaskUpdate.call.<locals>.<listcomp>¶   s   € ÐFÐFÐF �q”tÐFÐFÐFr'   c                 ó$   •— g | ]}|‰v¯|‰v ¯
|‘ŒS r&   r&   )r5   r6   Úcurrent_blocksÚexisted_idss     €€r(   r7   z#TaskUpdate.call.<locals>.<listcomp>¹   s8   ø€ ð ð ð àØ˜NÐ*Ð*¨q°KÐ/?Ð/?ð à/?Ð/?Ð/?r'   r   c                 ó$   •— g | ]}|‰v¯|‰v ¯
|‘ŒS r&   r&   )r5   r6   Úcurrent_blocked_byr:   s     €€r(   r7   z#TaskUpdate.call.<locals>.<listcomp>Ë   s9   ø€ ð ð ð àØÐ.Ð.Ð.°1¸Ð3CÐ3Cð à3CÐ3CÐ3Cr'   r   r   z	Task (id=z) has been deleted.)r1   r   r   r   zUpdate task (id=z) z, ú.z%No updates were made to the task (id=zR). Make sure you provided at least one field to update and the values are correct.r   zj

Task completed. Call TaskList now to find your next available task or see if your work unblocked others.)Ú
isinstancer   r   r+   Ú	enumerateÚtasks_contextÚtasksr4   r	   r   r   ÚERRORÚappendr   r   ÚblocksÚ_update_block_relationÚ
blocked_byÚpopÚremover2   r   Úitemsr   Újoin)Úselfr-   r   r   r   r   r   r   r   r   ÚindexÚiÚtaskÚupdated_fieldsÚ
new_blocksÚblock_idÚnew_blocked_byÚblocked_by_idÚkÚvÚresr<   r9   r:   s                        @@@r(   ÚcallzTaskUpdate.call‡   sã  øøøè è € õ ˜,­
Ñ3Ô3ð 	å,ð+˜$œ)ð +ð +Øð+ð +ð +ñô ð ð
 ˆÝ  Ô!;Ô!AÑBÔBð 	ð 	‰GˆAˆtØŒw˜'Ò!Ð!Ø�øàˆ=ÝåðCØ(/ðCð Cð Cðñ ô ðõ &Ô+ðñ ô ð ð ˆàð 	FØ×!Ò! )Ñ,Ô,Ð,Ø>EˆLÔ&Ô,¨UÔ3Ô;àÐ"Ø×!Ò! -Ñ0Ô0Ð0ØBMˆLÔ&Ô,¨UÔ3Ô?àFÐF \Ô%?Ô%EÐFÑFÔFˆØð 	Ø)Ô7Ô=¸eÔDÔKˆNðð ð ð ð à#ðñ ô ˆJð
 ð Ø×%Ò% lÑ3Ô3Ð3Ø *ð ð �HØ×/Ò/ØØ Ø$ñô ð ð ð Ð%Ø!-Ô!;Ô!AØô"äð ðð ð ð ð à'ðñ ô ˆNð
 ð Ø×%Ò%Ð&6Ñ7Ô7Ð7Ø%3ð ð �MØ×/Ò/Ø%ØØ$ñô ð ð ð ð 	CØ˜Ò"Ð"àÔ*Ô0×4Ò4°UÑ;Ô;Ð;à(Ô6Ô<ð 8ð 8�DØ $¤+Ð-Ð-Øœ×*Ò*¨7Ñ3Ô3Ð3à $¤/Ð1Ð1Øœ×.Ò.¨wÑ7Ô7Ð7øÝ å!Ø!I¨WÐ!IÐ!IÐ!Iðñ ô ððñ ô ð ð ×!Ò! (Ñ+Ô+Ð+Ø<BˆLÔ&Ô,¨UÔ3Ô9àÐØ×!Ò! 'Ñ*Ô*Ð*Ø<AˆLÔ&Ô,¨UÔ3Ô9àð 		LØ×!Ò! *Ñ-Ô-Ð-Ø ŸšÑ(Ô(ð Lð L‘��1Ø�9Ø Ô.Ô4°UÔ;ÔD×HÒHØØñô ð ð ð
 KL�LÔ.Ô4°UÔ;ÔDÀQÑGÐGàð 	ØL WÐLÐL°·	²	¸.Ñ0IÔ0IÐLÐLÐLˆCˆCð+¸ð +ð +ð +ð ð Ô%Ô+¨EÔ2Ô8¸KÒGÐGØðGñˆCõ
 ¥)°Ð"5Ñ"5Ô"5Ð!6Ð7Ñ7Ô7Ð7r'   rQ   rS   c                 óÜ   — |j         j        D ]^}|j        | k    r#||j        vr|j                             |¦  «         |j        |k    r#| |j        vr|j                             | ¦  «         Œ_dS )ac  Update the block relationship between the tasks.

        Args:
            block_id (`str`):
                The id of the task that blocks the other tasks.
            blocked_by_id (`str`):
                The id of the task blocked by the task of `block_id`.
            _agent_state (`AgentState`):
                The agent state to update.
        N)r@   rA   r4   rD   rC   rF   )rQ   rS   r-   rN   s       r(   rE   z!TaskUpdate._update_block_relation  s‚   € ð" !Ô.Ô4ð 	1ð 	1ˆDØŒw˜(Ò"Ð" }¸D¼KÐ'GÐ'GØ”×"Ò" =Ñ1Ô1Ð1àŒw˜-Ò'Ð'¨H¸D¼OÐ,KÐ,KØ”×&Ò& xÑ0Ô0Ð0øð	1ð 	1r'   )NNNNNNN)r   r   r    r!   r+   r"   r#   r   r   Úmodel_json_schemar,   r%   r   r$   r   r	   rW   ÚstaticmethodrE   r&   r'   r(   r*   r*   6   s}  € € € € € € Ø,Ð,à€Dˆ#ÐÐÑðH€K�ð Hð Hñ HðT +×<Ò<Ñ>Ô>€L�$Ð>Ð>Ñ>ð #Ø"&Ø'+àØ+/Ø Ø $ðF8ð F8à ðF8ð ðF8ð �t‘ð	F8ð
 ˜4‘ZðF8ð ˜”I Ñ$ðF8ð ÐHÔIØ
ñðF8ð ˜Sœ	 DÑ(ðF8ð �T‰zðF8ð ˜‘+ðF8ð 
ðF8ð F8ð F8ð F8ðP ð1Øð1àð1ð !ð1ð 
ð	1ð 1ð 1ñ „\ð1ð 1ð 1r'   r*   N)r!   Útypingr   Úpydanticr   r   Ú_task_tool_baser   Ú	_responser	   r2   r   Ú	exceptionr   Úmessager   r   r   r*   r&   r'   r(   ú<module>ra      sþ   ðà "Ð "Ø Ð Ð Ð Ð Ð à %Ð %Ð %Ð %Ð %Ð %Ð %Ð %à *Ð *Ð *Ð *Ð *Ð *Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1ð%ð %ð %ð %ð %˜	ñ %ô %ð %ðPo1ð o1ð o1ð o1ð o1�ñ o1ô o1ð o1ð o1ð o1r'   