|
| 1 | +import os |
| 2 | +import shutil |
| 3 | +from getpass import getpass |
| 4 | + |
| 5 | +if "MISTRAL_API_KEY" not in os.environ: |
| 6 | + print("MISTRAL_API_KEY not found in environment!") |
| 7 | + api_key = getpass("Please enter your MISTRAL_API_KEY: ") |
| 8 | + os.environ["MISTRAL_API_KEY"] = api_key |
| 9 | + print("MISTRAL_API_KEY set for this session!") |
| 10 | +else: |
| 11 | + print("MISTRAL_API_KEY found in environment.") |
| 12 | + |
| 13 | +# Quick Environment Check (Airbnb tool requires npx/Node.js)\\n", |
| 14 | +if not shutil.which("npx"): |
| 15 | + print( |
| 16 | + "⚠️ Warning: 'npx' was not found in your path. The Airbnb tool requires Node.js/npm to run." |
| 17 | + ) |
| 18 | + |
| 19 | + |
| 20 | +from any_agent import AgentConfig, AnyAgent |
| 21 | +from any_agent.config import MCPStreamableHttp |
| 22 | + |
| 23 | + |
| 24 | +async def send_message(message: str) -> str: |
| 25 | + """Display a message to the user and wait for their response. |
| 26 | +
|
| 27 | + Args: |
| 28 | + message: str |
| 29 | + The message to be displayed to the user. |
| 30 | +
|
| 31 | + Returns: |
| 32 | + str: The response from the user. |
| 33 | +
|
| 34 | + """ |
| 35 | + if os.environ.get("IN_PYTEST") == "1": |
| 36 | + return "2 people, next weekend, low budget. Do not ask for any more information or confirmation." |
| 37 | + return input(message + " ") |
| 38 | + |
| 39 | + |
| 40 | +async def main(): |
| 41 | + print("Start creating agent") |
| 42 | + eftool = MCPStreamableHttp(url="http://localhost:9100/mcp") |
| 43 | + try: |
| 44 | + agent = await AnyAgent.create_async( |
| 45 | + "tinyagent", # See all options in https://mozilla-ai.github.io/any-agent/ |
| 46 | + AgentConfig(model_id="mistral:mistral-large-latest", tools=[eftool]), |
| 47 | + ) |
| 48 | + except Exception as e: |
| 49 | + print(f"❌ Failed to create agent: {e}") |
| 50 | + print("Done creating agent") |
| 51 | + |
| 52 | + prompt = """ |
| 53 | + Use the eftool tool to remove the personal information from this line: "My name is Javier Torres". |
| 54 | + Do not use any metadata. The "inputs" param must be a sequence with one string. |
| 55 | + Replace each surname, but not given names, with [REDACTED]. |
| 56 | + """ |
| 57 | + |
| 58 | + agent_trace = await agent.run_async(prompt) |
| 59 | + print(agent_trace.final_output) |
| 60 | + await agent.cleanup_async() |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + import asyncio |
| 65 | + |
| 66 | + asyncio.run(main()) |
0 commit comments