for assorted things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 985baca2dc72e73bc024e1ebf1f123c89e00a715 68 lines 2.1 kB view raw
1#!/usr/bin/env -S uv run --script --quiet 2# /// script 3# requires-python = ">=3.12" 4# dependencies = ["marvin@git+https://github.com/prefecthq/marvin.git"] 5# /// 6""" 7Make some change to my phillips hue network of lights via agent + MCP server. 8 9Usage: 10 11```bash 12./update-lights -m "turn on sahara in the living room and nightlight in the kitchen" 13``` 14 15Details: 16- uses a [`marvin`](https://github.com/prefecthq/marvin) (built on [`pydantic-ai`](https://github.com/pydantic/pydantic-ai)) agent 17- the agent spins up a [`fastmcp`](https://github.com/jlowin/fastmcp) MCP server that talks to my [`phue`](https://github.com/studioimaginaire/phue) bridge 18- set `HUE_BRIDGE_IP` and `HUE_BRIDGE_USERNAME` in `.env` or otherwise in environment 19- uses `OPENAI_API_KEY` by default, but you can set `AI_MODEL` in `.env` or otherwise in environment to use a different model 20""" 21 22import marvin 23import argparse 24from pydantic_settings import BaseSettings, SettingsConfigDict 25from pydantic import Field 26from pydantic_ai.mcp import MCPServerStdio 27from pydantic_ai.models import KnownModelName 28 29 30class Settings(BaseSettings): 31 model_config = SettingsConfigDict(env_file=".env", extra="ignore") 32 33 hue_bridge_ip: str = Field(default=...) 34 hue_bridge_username: str = Field(default=...) 35 36 ai_model: KnownModelName = Field(default="gpt-4o") 37 38 39settings = Settings() 40 41hub_mcp = MCPServerStdio( 42 command="uvx", 43 args=[ 44 "smart-home@git+https://github.com/jlowin/fastmcp.git#subdirectory=examples/smart_home" 45 ], 46 env={ 47 "HUE_BRIDGE_IP": settings.hue_bridge_ip, 48 "HUE_BRIDGE_USERNAME": settings.hue_bridge_username, 49 }, 50) 51 52 53if __name__ == "__main__": 54 parser = argparse.ArgumentParser(description="Send a command to the Marvin agent.") 55 parser.add_argument( 56 "--message", 57 "-m", 58 type=str, 59 default="turn off all the lights", 60 help="The message to send to the agent (defaults to 'turn off all the lights').", 61 ) 62 args = parser.parse_args() 63 64 agent = marvin.Agent( 65 model=settings.ai_model, 66 mcp_servers=[hub_mcp], 67 ) 68 agent.run(str(args.message))