| 1 | import os |
| 2 | from pyagentspec.adapters.langgraph import AgentSpecLoader |
| 3 | from pyagentspec.agent import Agent |
| 4 | from pyagentspec.llms import OpenAiConfig |
| 5 | from respan import Respan |
| 6 | from respan_instrumentation_agentspec import AgentSpecInstrumentor |
| 7 | |
| 8 | os.environ["OPENAI_API_KEY"] = os.environ["RESPAN_API_KEY"] |
| 9 | os.environ["OPENAI_BASE_URL"] = "https://api.respan.ai/api" |
| 10 | |
| 11 | respan = Respan( |
| 12 | app_name="agentspec-haiku-agent", |
| 13 | instrumentations=[ |
| 14 | AgentSpecInstrumentor(workflow_name="agentspec_haiku_agent") |
| 15 | ], |
| 16 | ) |
| 17 | |
| 18 | try: |
| 19 | agent = Agent( |
| 20 | name="haiku_assistant", |
| 21 | description="A helpful assistant that writes haikus.", |
| 22 | llm_config=OpenAiConfig(name="openai", model_id="gpt-4.1-nano"), |
| 23 | system_prompt="You are a helpful assistant. Respond only with a haiku.", |
| 24 | ) |
| 25 | |
| 26 | langgraph_agent = AgentSpecLoader().load_component(agent) |
| 27 | result = langgraph_agent.invoke( |
| 28 | input={"messages": [{"role": "user", "content": "Write a haiku about recursion."}]} |
| 29 | ) |
| 30 | print(result["messages"][-1].content) |
| 31 | finally: |
| 32 | respan.shutdown() |
| 33 | respan.flush() |