-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(examples): merge validation fixes phases 2-4 into main (stacked on #1855) #1893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3f14324
bfa9d0c
3d3fdd0
4cc066c
b120e13
f1300ac
e89b50d
763f7c8
a55867b
9c334bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,8 +57,8 @@ def main(): | |
| agent = Agent( | ||
| name="SecureAgent", | ||
| instructions="You are a file management assistant.", | ||
| policy=engine | ||
| ) | ||
| agent.policy = engine | ||
|
Comment on lines
57
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Check if PolicyConfig pattern exists and how policy is used in other examples
# Search for PolicyConfig usage
ast-grep --pattern 'class PolicyConfig'
# Search for policy parameter usage in Agent constructor
rg -n -C3 'Agent\(' --type=py | rg -C3 'policy='
# Search for post-construction policy assignment pattern
rg -n 'agent\.policy\s*=' --type=pyRepository: MervinPraison/PraisonAI Length of output: 22058 🏁 Script executed: #!/bin/bash
set -euo pipefail
# 1) Inspect the example around the flagged lines
echo "### examples/policy/basic_policy.py:57-80"
sed -n '50,90p' examples/policy/basic_policy.py
# 2) Find the Agent class definition and show its __init__ signature
echo
echo "### Locate Agent class"
fd -a "agent.py" . || true
fd -a "*agent*" src examples -t f || true
# Prefer AST-grep to find the class and __init__ params
echo
echo "### AST-grep: class Agent and __init__"
ast-grep --pattern $'class Agent { $$$ }' || true
# Fallback: text search for def __init__ with policy inside Agent-related files
echo
echo "### rg: Agent __init__ signature candidates"
rg -n --type=py "class Agent\b" -S src/praisonai-agents/praisonaiagents || true
rg -n --type=py "def __init__\(" -S src/praisonai-agents/praisonaiagents | rg -n "Agent|agent" || true
rg -n --type=py "policy\s*=" -S examples src/praisonai-agents/praisonaiagents | head -n 50
# 3) Search for Agent(policy=...) more robustly (multiline friendly)
echo
echo "### rg multiline-ish: Agent( ... policy="
rg -n --type=py "Agent\s*\(\s*[\s\S]{0,200}policy\s*=" src examples || trueRepository: MervinPraison/PraisonAI Length of output: 50685 🏁 Script executed: #!/bin/bash
set -euo pipefail
# 1) Read the Python Agent implementation used by examples/policy/basic_policy.py
echo "### Candidate Agent python files (praisonai-agents)"
fd -a "agent.py" src/praisonai-agents/praisonaiagents/agent -t f
# Print the most likely one(s)
for f in src/praisonai-agents/praisonaiagents/agent/agent.py src/praisonai-agents/praisonaiagents/agent/*.py; do
if [ -f "$f" ]; then
echo "---- $f"
rg -n "class Agent\b|def __init__\(" "$f" | head -n 30 || true
rg -n "\bpolicy\b" "$f" | head -n 80 || true
fi
done
# 2) Focused: show Agent __init__ signature where 'policy' is mentioned
echo
echo "### Focused search for policy in python Agent __init__"
rg -n --type=py "def __init__\(" src/praisonai-agents/praisonaiagents/agent | head -n 50
rg -n --type=py -C3 "\bpolicy\b" src/praisonai-agents/praisonaiagents/agent/agent.py src/praisonai-agents/praisonaiagents/agent/*.py || true
# 3) Scan examples for policy usage patterns
echo
echo "### examples: PolicyConfig usage"
rg -n --type=py "PolicyConfig\s*\(" examples | head -n 50 || true
echo
echo "### examples: direct Agent(..., policy=...)"
rg -n --type=py -S "Agent\s*\(" examples | rg -n "policy\s*=" | head -n 80 || true
echo
echo "### examples: post-construction agent.policy assignment"
rg -n --type=py "agent\.policy\s*=" examples | head -n 50 || trueRepository: MervinPraison/PraisonAI Length of output: 27379 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect the flagged example end-to-end enough to see how `engine` is created.
echo "### examples/policy/basic_policy.py (top to ~90)"
sed -n '1,120p' examples/policy/basic_policy.py
# Inspect Agent.__init__ signature/doc around where `policy` is defined (agent.py is large).
echo
echo "### src/praisonai-agents/praisonaiagents/agent/agent.py: __init__ policy parameter context"
python3 - <<'PY'
import itertools
path="src/praisonai-agents/praisonaiagents/agent/agent.py"
start=480
end=920
with open(path,'r',encoding='utf-8') as f:
for i,line in enumerate(f,1):
if start<=i<=end:
print(f"{i}:{line.rstrip()}")
PY
# Inspect how policy is applied during execution (quick targeted searches).
echo
echo "### Search for policy usage inside agent.py (top-level)"
rg -n "policy" src/praisonai-agents/praisonaiagents/agent/agent.py | head -n 80
echo
echo "### Search for PolicyEngine/PolicyConfig classes"
fd -a "engine.py|Engine|policy_engine|PolicyEngine" src/praisonai-agents/praisonaiagents/policy -t f || true
rg -n --type=py "class PolicyEngine|PolicyEngine|PolicyConfig" src/praisonai-agents/praisonaiagents/policy -S || true
# Inspect policy engine implementation and whether it is configured via PolicyConfig.
echo
echo "### src/praisonai-agents/praisonaiagents/policy/* (policy engine/config definitions)"
for f in $(fd -a -t f src/praisonai-agents/praisonaiagents/policy); do
rg -n --type=py "class (PolicyEngine|PolicyConfig)\b" "$f" && echo "---- $f"
done 2>/dev/null || true
# Finally, scan for any other examples that do Agent(policy=PolicyConfig(...)) for policy engine usage.
echo
echo "### examples: Agent(..., policy=...) where policy is present (broader)"
rg -n --type=py "Agent\s*\(" examples | rg -n "policy\s*=" | head -n 100 || trueRepository: MervinPraison/PraisonAI Length of output: 31742 🏁 Script executed: #!/bin/bash
set -euo pipefail
# 1) Re-print the full Agent.__init__ signature area (small window) and search for "policy" inside it
echo "### Print Agent.__init__ signature lines 500-590"
sed -n '500,590p' src/praisonai-agents/praisonaiagents/agent/agent.py
echo
echo "### rg for 'policy' within the Agent.__init__ signature window"
rg -n --type=py "policy\s*:" -n src/praisonai-agents/praisonaiagents/agent/agent.py | head -n 50 || true
# 2) Look for any config default resolver / consolidated param handling for policy
echo
echo "### rg for consolidated handling of policy in agent.py"
rg -n --type=py "PolicyConfig|policy\s*=|apply_config_defaults\(\"policy\"\)|param_name=\"policy\"|resolve\(.*policy" src/praisonai-agents/praisonaiagents/agent/agent.py | head -n 120
# 3) Find where policy is actually used during execution/tool checks
echo
echo "### rg for self._policy usage"
rg -n --type=py "self\._policy|_policy" src/praisonai-agents/praisonaiagents/agent/agent.py | head -n 120
# 4) Search in whole python package for Agent(policy=...) usage (beyond examples)
echo
echo "### rg: Agent(policy=...) across src/praisonai-agents"
rg -n --type=py "Agent\s*\([^)]*policy\s*=" src/praisonai-agents | head -n 80 || trueRepository: MervinPraison/PraisonAI Length of output: 6858 🏁 Script executed: #!/bin/bash
set -euo pipefail
AGENT_PY="src/praisonai-agents/praisonaiagents/agent/agent.py"
echo "### All occurrences of 'policy' in $AGENT_PY (first 80)"
rg -n "policy" "$AGENT_PY" | head -n 80
echo
echo "### Agent policy resolution block (around line 800-900)"
python3 - <<'PY'
path="src/praisonai-agents/praisonaiagents/agent/agent.py"
for start,end in [(760,880),(880,1020),(1860,2020),(2020,2210)]:
print(f"\n--- {start}-{end} ---")
with open(path,'r',encoding='utf-8') as f:
for i,line in enumerate(f,1):
if start<=i<=end:
print(f"{i}:{line.rstrip()}")
PY
echo
echo "### Look for 'param_name=\"policy\"' or 'policy' passed to resolve/apply_config_defaults"
rg -n --type=py "param_name\s*=\s*\"policy\"|apply_config_defaults\\(\"policy\"\\)|resolve\\(.*policy" "$AGENT_PY" || true
echo
echo "### Search for any mention of PolicyEngine/PolicyConfig in Agent python code"
rg -n --type=py "PolicyEngine|PolicyConfig" src/praisonai-agents/praisonaiagents/agent | head -n 50 || trueRepository: MervinPraison/PraisonAI Length of output: 30826 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Show PolicyEngine/PolicyConfig definitions relevant to configuration expectations
echo "### src/praisonai-agents/praisonaiagents/policy/engine.py"
sed -n '1,120p' src/praisonai-agents/praisonaiagents/policy/engine.py
echo
echo "### src/praisonai-agents/praisonaiagents/policy/config.py (top + usage snippet)"
sed -n '1,120p' src/praisonai-agents/praisonaiagents/policy/config.py
echo
echo "### src/praisonai-agents/praisonaiagents/policy/config.py (end of file / helpers if any)"
tail -n 80 src/praisonai-agents/praisonaiagents/policy/config.py
echo
echo "### src/praisonai-agents/praisonaiagents/policy/__init__.py"
sed -n '1,120p' src/praisonai-agents/praisonaiagents/policy/__init__.py
echo
echo "### Scan for any docs/example using Agent(policy=PolicyConfig(...)) in python agent codebase"
rg -n --type=py "Agent\s*\(\s*policy\s*=" src/praisonai-agents | head -n 50 || trueRepository: MervinPraison/PraisonAI Length of output: 13060 🏁 Script executed: #!/bin/bash
set -euo pipefail
# 1) Confirm what praisonaiagents.Agent exports
echo "### src/praisonai-agents/praisonaiagents/__init__.py"
sed -n '1,120p' src/praisonai-agents/praisonaiagents/__init__.py
echo
echo "### src/praisonai-agents/praisonaiagents/agent/__init__.py"
sed -n '1,120p' src/praisonai-agents/praisonaiagents/agent/__init__.py
# 2) Search for any Python Agent __init__ that has a 'policy' parameter in its signature
echo
echo "### Search: Python Agent __init__ signatures that mention 'policy' (single-line)"
rg -n --type=py "def __init__\([^)]*policy[^)]*\)" src/praisonai-agents | head -n 50 || true
echo
echo "### Search: broader 'policy' near Agent __init__ (within same file)"
rg -n --type=py "def __init__\(" src/praisonai-agents/praisonaiagents/agent | head -n 50 || true
# 3) Check PolicyEngine supports PolicyConfig input (already saw config param, but confirm usage)
echo
echo "### Search in policy/engine.py for PolicyConfig usage"
rg -n "PolicyConfig" src/praisonai-agents/praisonaiagents/policy/engine.py
echo
echo "### Search examples for PolicyEngine(PolicyConfig"
rg -n --type=py "PolicyEngine\s*\(\s*PolicyConfig" examples src || trueRepository: MervinPraison/PraisonAI Length of output: 13557 Clarify policy configuration API:
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| print("\n--- Agent with Policy Enforcement Created ---") | ||
| print(f"Agent: {agent.name}") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,9 +60,10 @@ | |
| process="sequential", output="verbose" | ||
| ) | ||
|
|
||
| print("Starting hierarchical agent generation...") | ||
| result = agents_system.start() | ||
| if __name__ == "__main__": | ||
| print("Starting hierarchical agent generation...") | ||
| result = agents_system.start() | ||
|
|
||
| print(f"\nHierarchical Result: {result[:200]}...") | ||
| print("\n✅ AutoAgents hierarchical generation complete!") | ||
| print("Demonstrated coordinated hierarchical workflow between manager and specialist agents.") | ||
| print(f"\nHierarchical Result: {str(result)[:200]}...") | ||
| print("\n✅ AutoAgents hierarchical generation complete!") | ||
| print("Demonstrated coordinated hierarchical workflow between manager and specialist agents.") | ||
|
Comment on lines
+63
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Root cause: partial entrypoint-guard migration still leaves top-level side effects. 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from praisonaiagents import Agent | ||
|
|
||
| agent = Agent(name="TweetAgent", instructions="Create a Tweet based on the topic provided") | ||
| agent.launch(port=8080, protocol="mcp") | ||
| if __name__ == "__main__": | ||
| agent = Agent(name="TweetAgent", instructions="Create a Tweet based on the topic provided") | ||
| agent.launch(port=8080, protocol="mcp", path="/") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,9 +90,18 @@ def main(): | |
|
|
||
| if result: | ||
| print("\n🔍 Analysis Results:") | ||
| for task_id, task_result in result["task_results"].items(): | ||
| task_results = result.get("task_results") if isinstance(result, dict) else result | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shared result-parsing bug: missing default for Both files use 🤖 Prompt for AI Agents |
||
| if isinstance(task_results, dict): | ||
| iterable = task_results.items() | ||
| elif isinstance(task_results, list): | ||
| iterable = enumerate(task_results) | ||
| else: | ||
| iterable = [("result", task_results)] | ||
|
|
||
| for task_id, task_result in iterable: | ||
| print(f"\nTask {task_id}:") | ||
| print(task_result.raw) | ||
| raw_value = getattr(task_result, "raw", None) | ||
| print(raw_value if raw_value is not None else str(task_result)) | ||
| else: | ||
| print("❌ Failed to capture and analyze camera feed") | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add explicit error handling for unsupported span objects.
The helper silently does nothing when the span supports neither
set_attribute()nor anattributesdict. For an example demonstrating observability patterns, this silent failure could confuse users who copy this code—attributes won't appear in traces without any indication why.As per coding guidelines, you should "fail fast with clear error messages; include remediation hints in exceptions."
🛡️ Proposed fix to add explicit error handling
def set_span_attr(span, key, value): """Set span attribute safely across observability implementations.""" if hasattr(span, "set_attribute"): span.set_attribute(key, value) return attrs = getattr(span, "attributes", None) if attrs is not None: attrs[key] = value + return + raise AttributeError( + f"Span object does not support attribute setting. " + f"Expected 'set_attribute' method or 'attributes' dict, got {type(span).__name__}" + )🤖 Prompt for AI Agents
Source: Coding guidelines