Create a file called first_agent.py and set up
your API key:
Copy
import osfrom praisonaiagents import Agent# Set your API key# Option 1: Set it in your environment (recommended)# export OPENAI_API_KEY=your_key_here# Option 2: Set it in your code (not recommended for production)# os.environ["OPENAI_API_KEY"] = "your_key_here"
# Create a research assistant agentresearch_assistant = Agent( name="ResearchAssistant", instructions=""" You are a helpful research assistant that provides clear, accurate information on various topics. When answering: 1. Be concise and to the point 2. Explain complex concepts in simple terms 3. When appropriate, organize information with bullet points 4. If you don't know something, admit it instead of guessing """)
# Start the agent with a specific queryresponse = research_assistant.start("Explain how solar panels work in simple terms")# Print the responseprint(response)
Try changing the question to see how your agent responds to
different topics:
Copy
# Try different questionsresponse = research_assistant.start("What are the benefits of exercise?")# orresponse = research_assistant.start("How does artificial intelligence work?")
You can change how your agent behaves by adjusting its
instructions:
Copy
# Create an agent with different instructionscreative_writer = Agent( name="CreativeWriter", instructions=""" You are a creative writer that specializes in short, engaging stories. Your writing should: 1. Include vivid descriptions 2. Have interesting characters 3. Include some dialogue 4. Have a clear beginning, middle, and end """)# Ask for a storystory = creative_writer.start("Write a short story about a lost dog finding its way home")print(story)