|
| 1 | +import argparse |
| 2 | +import asyncio |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +from agents import Agent, Runner, ShellTool, ShellToolLocalSkill, trace |
| 6 | +from examples.tools.shell import ShellExecutor |
| 7 | + |
| 8 | +SKILL_NAME = "csv-workbench" |
| 9 | +SKILL_DIR = Path(__file__).resolve().parent / "skills" / SKILL_NAME |
| 10 | + |
| 11 | + |
| 12 | +def build_local_skill() -> ShellToolLocalSkill: |
| 13 | + return { |
| 14 | + "name": SKILL_NAME, |
| 15 | + "description": "Analyze CSV files and return concise numeric summaries.", |
| 16 | + "path": str(SKILL_DIR), |
| 17 | + } |
| 18 | + |
| 19 | + |
| 20 | +async def main(model: str) -> None: |
| 21 | + local_skill = build_local_skill() |
| 22 | + |
| 23 | + with trace("local_shell_skill_example"): |
| 24 | + agent1 = Agent( |
| 25 | + name="Local Shell Agent (Local Skill)", |
| 26 | + model=model, |
| 27 | + instructions="Use the available local skill to answer user requests.", |
| 28 | + tools=[ |
| 29 | + ShellTool( |
| 30 | + environment={ |
| 31 | + "type": "local", |
| 32 | + "skills": [local_skill], |
| 33 | + }, |
| 34 | + executor=ShellExecutor(), |
| 35 | + ) |
| 36 | + ], |
| 37 | + ) |
| 38 | + |
| 39 | + result1 = await Runner.run( |
| 40 | + agent1, |
| 41 | + ( |
| 42 | + "Use the csv-workbench skill. Create /tmp/test_orders.csv with columns " |
| 43 | + "id,region,amount,status and at least 6 rows. Then report total amount by " |
| 44 | + "region and count failed orders." |
| 45 | + ), |
| 46 | + ) |
| 47 | + print(f"Agent: {result1.final_output}") |
| 48 | + |
| 49 | + agent2 = Agent( |
| 50 | + name="Local Shell Agent (Reuse)", |
| 51 | + model=model, |
| 52 | + instructions="Reuse the existing local shell and answer concisely.", |
| 53 | + tools=[ |
| 54 | + ShellTool( |
| 55 | + environment={ |
| 56 | + "type": "local", |
| 57 | + }, |
| 58 | + executor=ShellExecutor(), |
| 59 | + ) |
| 60 | + ], |
| 61 | + ) |
| 62 | + |
| 63 | + result2 = await Runner.run( |
| 64 | + agent2, |
| 65 | + "Run `ls -la /tmp/test_orders.csv`, then summarize in one sentence.", |
| 66 | + ) |
| 67 | + print(f"Agent (reuse): {result2.final_output}") |
| 68 | + |
| 69 | + |
| 70 | +if __name__ == "__main__": |
| 71 | + parser = argparse.ArgumentParser() |
| 72 | + parser.add_argument( |
| 73 | + "--model", |
| 74 | + default="gpt-5.2", |
| 75 | + help="Model name to use.", |
| 76 | + ) |
| 77 | + args = parser.parse_args() |
| 78 | + asyncio.run(main(args.model)) |
0 commit comments