@@ -1751,9 +1751,13 @@ def to_a2a(
1751
1751
lifespan = lifespan ,
1752
1752
)
1753
1753
1754
- async def to_cli (self : Self , deps : AgentDepsT = None ) -> None :
1754
+ async def to_cli (self : Self , deps : AgentDepsT = None , prog_name : str = 'pydantic-ai' ) -> None :
1755
1755
"""Run the agent in a CLI chat interface.
1756
1756
1757
+ Args:
1758
+ deps: The dependencies to pass to the agent.
1759
+ prog_name: The name of the program to use for the CLI. Defaults to 'pydantic-ai'.
1760
+
1757
1761
Example:
1758
1762
```python {title="agent_to_cli.py" test="skip"}
1759
1763
from pydantic_ai import Agent
@@ -1768,29 +1772,24 @@ async def main():
1768
1772
1769
1773
from pydantic_ai ._cli import run_chat
1770
1774
1771
- # TODO(Marcelo): We need to refactor the CLI code to be able to be able to just pass `agent`, `deps` and
1772
- # `prog_name` from here.
1775
+ await run_chat (stream = True , agent = self , deps = deps , console = Console (), code_theme = 'monokai' , prog_name = prog_name )
1773
1776
1774
- await run_chat (
1775
- stream = True ,
1776
- agent = self ,
1777
- deps = deps ,
1778
- console = Console (),
1779
- code_theme = 'monokai' ,
1780
- prog_name = 'pydantic-ai' ,
1781
- )
1782
-
1783
- def to_cli_sync (self : Self , deps : AgentDepsT = None ) -> None :
1777
+ def to_cli_sync (self : Self , deps : AgentDepsT = None , prog_name : str = 'pydantic-ai' ) -> None :
1784
1778
"""Run the agent in a CLI chat interface with the non-async interface.
1785
1779
1780
+ Args:
1781
+ deps: The dependencies to pass to the agent.
1782
+ prog_name: The name of the program to use for the CLI. Defaults to 'pydantic-ai'.
1783
+
1786
1784
```python {title="agent_to_cli_sync.py" test="skip"}
1787
1785
from pydantic_ai import Agent
1788
1786
1789
1787
agent = Agent('openai:gpt-4o', instructions='You always respond in Italian.')
1790
1788
agent.to_cli_sync()
1789
+ agent.to_cli_sync(prog_name='assistant')
1791
1790
```
1792
1791
"""
1793
- return get_event_loop ().run_until_complete (self .to_cli (deps = deps ))
1792
+ return get_event_loop ().run_until_complete (self .to_cli (deps = deps , prog_name = prog_name ))
1794
1793
1795
1794
1796
1795
@dataclasses .dataclass (repr = False )
0 commit comments