Unit 5: Testing, Monitoring, and Deployment of AI Agents - Subjective Questions
CSE476 — Agentic Ai And Intelligent Automation • Practice Questions with Detailed Answers
20 questions
Define AI agent workflow testing. Explain the major levels at which an agentic workflow should be tested.
AI agent workflow testing is the systematic process of verifying that an AI agent correctly interprets inputs, selects tools, executes actions, maintains state, and produces acceptable outputs under expected and unexpected conditions.
Major testing levels include:
- Unit testing: Tests individual components such as prompt templates, parsers, memory modules, validators, and tool wrappers.
- Integration testing: Verifies interactions among the language model, tools, databases, APIs, and orchestration framework.
- Workflow testing: Evaluates complete multi-step paths, including planning, tool selection, retries, and termination.
- End-to-end testing: Tests the production-like system from user request to final response.
- Regression testing: Ensures that model, prompt, or code changes do not break previously successful behavior.
- Safety and adversarial testing: Checks resistance to prompt injection, unsafe tool usage, data leakage, and malicious inputs.
A good test suite combines deterministic assertions with semantic evaluation because AI outputs may vary while still being correct.
Describe a systematic strategy for testing a multi-step AI agent that uses external tools and maintains conversational memory.
A systematic strategy should test both individual modules and the complete sequence of agent decisions.
- Define expected behavior: Specify supported tasks, valid tools, output constraints, and stopping conditions.
- Create representative test cases: Include normal, ambiguous, incomplete, adversarial, and out-of-domain requests.
- Mock external tools: Replace live services with predictable test doubles so that failures can be reproduced.
- Test tool selection: Confirm that the agent chooses the correct tool and supplies valid arguments.
- Test memory behavior: Verify that relevant facts are retained, irrelevant data is ignored, and session boundaries prevent data leakage.
- Test multi-step execution: Validate plans, intermediate results, retries, fallback logic, and termination.
- Inject failures: Simulate timeouts, malformed API responses, unavailable services, and rate limits.
- Evaluate final answers: Check factual correctness, relevance, citation quality, safety, and format compliance.
- Run regression tests: Store successful scenarios and execute them after changes to prompts, models, tools, or code.
This layered strategy makes nondeterministic agent behavior easier to diagnose and provides confidence before deployment.
Explain the principal debugging techniques used for AI agents. How does debugging an agent differ from debugging conventional deterministic software?
Important AI agent debugging techniques include:
- Trace inspection: Record prompts, model responses, plans, tool calls, observations, and final outputs.
- Step-by-step replay: Reproduce a failed execution using the same input, state, model version, and tool responses.
- Prompt inspection: Examine instructions for ambiguity, conflicts, missing constraints, or excessive context.
- Tool-call validation: Check tool names, argument schemas, permissions, responses, and exception handling.
- State inspection: Review short-term memory, long-term memory, checkpoints, and conversation history.
- Input minimization: Reduce a failing case to the smallest input that still produces the error.
- Controlled experiments: Change one variable at a time, such as the model, temperature, prompt, or retrieval configuration.
- Failure injection: Deliberately create timeouts, invalid outputs, and dependency failures to test recovery.
Conventional software usually maps a given input to a predictable output. AI agents are often nondeterministic, context-sensitive, and dependent on probabilistic models and external tools. Therefore, agent debugging must examine not only code defects but also prompt quality, model behavior, retrieved context, execution trajectories, and evaluation uncertainty.
Distinguish between logging, monitoring, observability, and telemetry in the context of production AI agent systems.
- Logging records discrete events generated by the system, such as an incoming request, selected tool, validation failure, or exception. Logs provide detailed evidence for troubleshooting.
- Monitoring continuously tracks selected indicators and triggers alerts when predefined thresholds are crossed. Examples include high latency, excessive error rate, or low task success.
- Observability is the broader ability to understand the internal state of a system from its external outputs. It combines logs, metrics, traces, and contextual metadata to investigate unexpected failures.
- Telemetry is the automated collection and transmission of operational data from the agent system. It supplies the logs, metrics, traces, and events used by monitoring and observability platforms.
In short, telemetry is the collected data, logging is one form of that data, monitoring detects known problems, and observability helps investigate both known and unknown problems.
What telemetry should be collected for an AI agent? Discuss how telemetry can be collected without compromising privacy or security.
Useful telemetry for an AI agent includes:
- Request metadata: Timestamp, request identifier, session identifier, endpoint, and input size.
- Model metadata: Provider, model version, temperature, token counts, and response time.
- Execution traces: Planning steps, tool selections, tool durations, retries, and termination reason.
- Retrieval data: Query, document identifiers, relevance scores, and citation coverage.
- Quality indicators: Task success, validation score, hallucination flags, and user feedback.
- Operational metrics: Throughput, latency, error rate, availability, cost, memory use, and CPU or GPU utilization.
- Security events: Authentication failures, prompt-injection indicators, denied tool calls, and policy violations.
Privacy-preserving practices include:
- Redacting personally identifiable information and secrets before storage.
- Applying data minimization and collecting only information required for an operational purpose.
- Encrypting telemetry in transit and at rest.
- Using role-based access control and maintaining audit logs.
- Defining retention and deletion policies.
- Hashing or pseudonymizing user and session identifiers.
- Avoiding storage of complete prompts and responses unless consent, security, and governance requirements are satisfied.
Explain how distributed tracing can be applied to a multi-agent or tool-using AI workflow.
Distributed tracing represents a complete request as a trace and each operation within it as a span. A trace may contain spans for request preprocessing, planning, model inference, retrieval, tool execution, validation, and response generation.
Each span should record:
- Trace and parent-span identifiers.
- Start time, end time, and duration.
- Agent, model, prompt, and tool versions.
- Token usage and estimated cost.
- Tool arguments in redacted form and the result status.
- Retry count, error details, and validation outcome.
In a multi-agent system, trace context must be propagated when one agent delegates work to another or when a message enters a queue. This reconstructs the causal execution path across services.
Distributed tracing helps identify slow tools, repeated loops, unnecessary model calls, failed handoffs, and bottlenecks. Standards such as OpenTelemetry can provide consistent instrumentation, while sensitive prompt or user data should be redacted before spans are exported.
Define hallucination in AI agents and describe techniques for detecting hallucinated outputs.
A hallucination is an output that appears plausible but is unsupported, fabricated, factually incorrect, or inconsistent with trusted evidence. In agentic systems, hallucinations may also involve invented tool results, false claims of completed actions, or nonexistent citations.
Detection techniques include:
- Grounding checks: Compare claims against retrieved documents, databases, or verified tool outputs.
- Citation verification: Confirm that cited sources exist and support the associated statements.
- Natural language inference: Determine whether evidence entails, contradicts, or is unrelated to each claim.
- Rule and schema validation: Detect invalid identifiers, dates, ranges, formats, or unsupported fields.
- Independent model evaluation: Use a separate evaluator to score factual consistency, while recognizing that it can also make errors.
- Self-consistency testing: Generate multiple responses and identify unstable or contradictory claims.
- Execution verification: Confirm through tool logs that an action claimed by the agent actually occurred.
- Human review: Escalate high-risk or low-confidence outputs to a qualified reviewer.
Detection is strongest when several methods are combined rather than relying only on the agent's own confidence statement.
Design a hallucination detection and mitigation pipeline for a retrieval-augmented AI agent.
A suitable pipeline can contain the following stages:
- Input classification: Determine the domain, risk level, and whether authoritative evidence is required.
- Retrieval: Fetch relevant passages from approved and current sources, retaining document identifiers and relevance scores.
- Context quality check: Reject or broaden retrieval when evidence is missing, outdated, duplicated, or weakly relevant.
- Grounded generation: Instruct the model to answer only from supplied evidence and to cite supporting passages.
- Claim extraction: Break the generated response into atomic factual claims.
- Claim-evidence verification: Check whether each claim is supported, contradicted, or unsupported by the retrieved context.
- Citation validation: Verify that every citation exists and semantically supports the corresponding statement.
- Rule-based validation: Apply domain constraints, schema checks, numerical checks, and prohibited-content policies.
- Decision stage: Accept the response, regenerate it with improved evidence, return an uncertainty message, or send it for human review.
- Telemetry and learning: Record redacted failure patterns and add confirmed failures to the regression dataset.
A confidence score may combine groundedness, retrieval quality, citation coverage, and validator results. However, critical decisions should use explicit thresholds and human oversight instead of trusting a single probability score.
Compare rule-based, model-based, and human-in-the-loop validation methods for AI agent outputs.
Rule-based validation uses schemas, regular expressions, type checks, allowlists, business rules, and deterministic calculations.
- Advantages: Fast, inexpensive, reproducible, and easy to audit.
- Limitations: Poor at evaluating nuanced meaning and cannot cover every valid output variation.
Model-based validation uses another model, or a separate invocation, to judge relevance, groundedness, safety, or completeness.
- Advantages: Handles semantic and open-ended criteria at scale.
- Limitations: Can be biased, nondeterministic, vulnerable to prompt manipulation, and capable of hallucinating its evaluation.
Human-in-the-loop validation assigns uncertain or high-risk cases to trained reviewers.
- Advantages: Supports contextual judgment, accountability, and complex domain expertise.
- Limitations: Slower, more expensive, and subject to inconsistency among reviewers.
A production system commonly uses a layered approach: deterministic rules first, model-based evaluation for semantic quality, and human review for high-impact or low-confidence cases.
Explain suitable offline and online evaluation metrics for assessing an AI agent in production. Include relevant equations.
Offline metrics are measured on curated datasets before release:
- Task completion accuracy.
- Tool-selection accuracy.
- Argument or schema validity.
- Groundedness and citation correctness.
- Safety-policy compliance.
- Average steps and tokens per task.
- Regression pass rate.
If tasks succeed out of evaluated tasks, the task success rate is:
Online metrics describe real production behavior:
- Request volume and throughput.
- End-to-end latency percentiles such as p50, p95, and p99.
- Error, timeout, and retry rates.
- User satisfaction and escalation rate.
- Cost per successful task.
- Hallucination or groundedness failure rate.
- Availability and service-level objective compliance.
If the total processing cost is and the number of successful tasks is , then:
Metrics should be segmented by model version, agent version, use case, tool, and risk category. This prevents aggregate averages from hiding localized failures.
Compare common deployment strategies for AI agents: recreate, rolling, blue-green, canary, and shadow deployment.
- Recreate deployment: Stops the old version before starting the new one. It is simple but can cause downtime and makes rollback slower.
- Rolling deployment: Replaces instances gradually. It maintains availability but temporarily runs mixed versions and may complicate compatibility.
- Blue-green deployment: Maintains two complete environments. Traffic is switched from the current environment to the new one after validation. Rollback is fast, but infrastructure cost is higher.
- Canary deployment: Sends a small percentage of real traffic to the new version. Exposure is increased only when quality, latency, cost, and safety metrics remain acceptable.
- Shadow deployment: Sends copies of production requests to a new version without using its responses for users. It enables safe comparison but requires additional computing resources and careful privacy controls.
For nondeterministic AI agents, canary and shadow strategies are especially useful because they allow teams to compare task success, hallucination rate, tool behavior, latency, and cost before full promotion.
Describe how an AI agent can be deployed on Microsoft Azure using appropriate managed services.
A typical Azure deployment may include:
- Azure OpenAI Service: Provides access to hosted language and embedding models.
- Azure AI Foundry: Supports model, prompt, evaluation, and agent development workflows.
- Azure App Service, Azure Functions, or Azure Container Apps: Hosts the agent API and orchestration code.
- Azure Kubernetes Service: Supports complex, containerized systems that require advanced scaling and networking control.
- Azure AI Search: Provides vector, keyword, and hybrid retrieval for grounded generation.
- Azure Storage or Azure Cosmos DB: Stores documents, state, checkpoints, and conversation metadata.
- Azure API Management: Secures, publishes, throttles, and versions external APIs.
- Azure Key Vault: Protects API keys, certificates, and other secrets.
- Microsoft Entra ID: Provides identity, authentication, and role-based authorization.
- Azure Monitor and Application Insights: Collect logs, metrics, traces, exceptions, and dependency information.
The system should use managed identities where possible, private networking for sensitive workloads, autoscaling rules, content safety controls, encryption, and CI/CD-based releases. Model, prompt, retrieval index, tool, and agent versions should all be traceable for rollback and auditing.
Explain how an AI agent should be exposed as a secure and reliable API.
A production API should provide a stable interface between clients and the agent.
Key design considerations are:
- Request and response schemas: Use explicit validation for messages, session identifiers, tool permissions, and output structure.
- Authentication and authorization: Apply OAuth, managed identities, API keys, or signed tokens and enforce least privilege.
- API versioning: Maintain compatibility when prompts, tools, models, or response fields change.
- Rate limiting and quotas: Protect expensive model and tool resources from abuse.
- Timeouts and cancellation: Prevent requests from consuming resources indefinitely.
- Idempotency: Use idempotency keys for operations that create side effects so retries do not duplicate actions.
- Asynchronous execution: Use job identifiers, queues, callbacks, or polling for long-running tasks.
- Streaming: Stream tokens or events when low perceived latency is important.
- Error handling: Return consistent status codes and sanitized error messages without exposing prompts, secrets, or stack traces.
- Auditability: Assign correlation identifiers and record redacted execution traces.
An API gateway can additionally provide TLS termination, policy enforcement, analytics, caching, routing, and protection against excessive traffic.
Design a CI/CD pipeline for a production AI agent. Explain the quality gates that should be applied before release.
A CI/CD pipeline for an AI agent can include:
- Source control: Version application code, prompts, configurations, tool schemas, evaluation datasets, and infrastructure definitions.
- Static checks: Run linting, type checking, dependency scanning, secret detection, and infrastructure validation.
- Unit tests: Test parsers, validators, prompts, memory logic, and tool adapters using mocked dependencies.
- Integration tests: Verify model endpoints, retrieval, databases, tools, identity, and network policies in a test environment.
- Agent evaluations: Measure task success, groundedness, safety, tool correctness, latency, token usage, and cost on a fixed benchmark.
- Security testing: Test prompt injection, unauthorized tool access, data leakage, malicious files, and dependency vulnerabilities.
- Artifact creation: Build a signed container image and generate a software bill of materials.
- Staging deployment: Deploy with production-like configuration and run smoke and end-to-end tests.
- Progressive release: Use shadow, canary, or blue-green deployment.
- Post-deployment monitoring: Automatically compare live metrics with service-level objectives and rollback thresholds.
Quality gates should block promotion when critical tests fail, safety regressions occur, latency or cost exceeds limits, evaluation scores decline beyond tolerance, or vulnerabilities remain unresolved. Manual approval may be required for high-risk use cases.
Discuss the principal scalability considerations for an AI agent system that receives a rapidly increasing workload.
Important scalability considerations include:
- Stateless API instances: Keep durable state in external stores so that instances can scale horizontally.
- Autoscaling: Scale according to request rate, queue depth, latency, token throughput, CPU, GPU, or memory.
- Queue-based processing: Buffer bursts and process long-running tasks asynchronously.
- Provider quotas: Account for token-per-minute, request-per-minute, and concurrent-request restrictions.
- Rate limiting and backpressure: Reject, defer, or degrade requests when capacity is exhausted.
- Caching: Reuse safe model responses, tool results, embeddings, and retrieval results when freshness rules allow.
- Data-store scaling: Partition conversation state, vector indexes, and telemetry while managing consistency.
- Concurrency controls: Prevent duplicate actions, race conditions, and simultaneous updates to the same agent state.
- Graceful degradation: Use smaller models, reduced context, delayed noncritical tasks, or read-only modes during overload.
- Regional deployment: Reduce latency and improve resilience while meeting data residency requirements.
Scalability must be evaluated together with cost, model limits, safety, observability, and the correctness of stateful workflows.
Explain methods for optimizing the latency, throughput, and cost of an AI agent without significantly reducing response quality.
Performance can be optimized through several techniques:
- Model routing: Use smaller models for classification, extraction, and simple questions while reserving larger models for complex reasoning.
- Prompt reduction: Remove redundant instructions and irrelevant history to reduce input tokens.
- Context management: Summarize old messages and retrieve only relevant documents instead of sending complete knowledge bases.
- Parallel execution: Run independent retrieval operations or tool calls concurrently.
- Caching: Cache embeddings, retrieval results, deterministic tool outputs, and appropriate model responses.
- Streaming: Return partial responses to improve perceived latency.
- Connection reuse: Apply connection pooling and persistent clients for databases and APIs.
- Batching: Batch embeddings or similar background operations where latency requirements permit.
- Loop control: Set maximum steps, token budgets, deadlines, and termination checks to prevent runaway reasoning.
- Profiling: Use traces to identify the slowest model calls, tools, and storage operations.
Optimization should be validated using task success, groundedness, safety, p95 latency, and cost per successful task. Reducing cost per request is not beneficial if it causes more failures, retries, or human escalations.
Derive the concepts of availability, error rate, and service-level objective compliance for an AI agent service. How can error budgets guide releases?
If a service is operational for time during a total observation period , its availability is:
If out of requests fail, the request error rate is:
For an availability objective of over a period of length , the permitted downtime or error budget is:
Here, is expressed as a fraction. For example, if the objective is , then .
For AI agents, success should not be based only on HTTP status. A technically successful response may still be incorrect, unsafe, ungrounded, or incomplete. Therefore, service-level indicators may include:
- Valid responses completed within the latency target.
- Correct task completion.
- Successful tool execution.
- Grounded and policy-compliant output.
When the error budget is being consumed too rapidly, teams should pause risky releases, investigate regressions, improve reliability, or roll back. When sufficient budget remains, controlled experimentation and canary releases can continue.
Explain resilience and failure-recovery mechanisms required in a production-ready AI agent system.
A resilient AI agent should anticipate failures in models, tools, networks, storage, and orchestration.
Key mechanisms include:
- Timeouts: Bound the time allowed for model, tool, and database operations.
- Retries with exponential backoff: Retry transient failures while adding delays and random jitter to avoid synchronized traffic spikes.
- Circuit breakers: Temporarily stop requests to a failing dependency.
- Fallbacks: Switch to another model, region, tool, or simplified workflow when appropriate.
- Checkpointing: Persist workflow state so long-running tasks can resume after interruption.
- Idempotency: Ensure repeated requests do not duplicate side effects such as payments or messages.
- Dead-letter queues: Store repeatedly failed asynchronous tasks for inspection and controlled replay.
- Bulkheads: Isolate resource pools so failure in one tool or tenant does not exhaust the whole system.
- Loop and budget limits: Restrict maximum steps, retries, tokens, time, and cost.
- Human escalation: Transfer unresolved or high-risk cases to an operator with relevant context.
Recovery logic must be observable and tested through controlled fault injection rather than assumed to work.
What are the essential characteristics of a production-ready AI agent system? Provide a comprehensive readiness checklist.
A production-ready AI agent should satisfy the following checklist:
- Functional quality: Core workflows, edge cases, tools, memory, and termination conditions are tested.
- Groundedness: Important claims are supported by trusted evidence and valid citations.
- Safety: Prompt injection, harmful output, unauthorized actions, and sensitive-data leakage are mitigated.
- Validation: Structured outputs, tool arguments, business rules, and side effects are checked before execution.
- Security: Authentication, authorization, encryption, secret management, least privilege, and audit trails are implemented.
- Reliability: Timeouts, retries, circuit breakers, fallbacks, idempotency, and disaster recovery are available.
- Observability: Correlated logs, metrics, traces, quality indicators, alerts, and dashboards are configured.
- Scalability: Stateless services, autoscaling, queues, caching, quotas, and backpressure are planned.
- Performance: Latency, throughput, token use, and cost meet defined objectives.
- Deployment maturity: Versioning, automated tests, staged releases, rollback, and infrastructure as code are established.
- Governance: Ownership, risk classification, data retention, model documentation, and approval processes are defined.
- Operations: Runbooks, on-call procedures, incident response, human escalation, and post-incident reviews are prepared.
Production readiness is an ongoing operational discipline. Metrics, evaluation datasets, risks, and controls must be updated as user behavior, tools, models, and external dependencies change.
Describe how production drift and regressions can be detected and managed in an AI agent system.
Drift is a change in production inputs, user behavior, retrieved knowledge, tool responses, or output quality over time. A regression is a measurable decline caused by a change such as a new prompt, model, tool, index, or configuration.
Detection methods include:
- Monitoring changes in request topics, input length, language, and risk category.
- Tracking task success, groundedness, tool errors, human escalations, latency, and cost by version.
- Running scheduled evaluations on fixed benchmark datasets.
- Creating new tests from confirmed production failures.
- Comparing current and candidate versions through shadow traffic, canary releases, or A/B evaluation.
- Monitoring retrieval relevance and data freshness.
- Recording model, prompt, tool, policy, and index versions in every trace.
Management actions include rollback, traffic reduction, prompt correction, tool repair, retrieval re-indexing, threshold adjustment, and human review. Alerts should focus on statistically or operationally meaningful changes rather than isolated output variation. After remediation, the failure should be added to the regression suite to reduce the chance of recurrence.
Define AI agent workflow testing. Explain the major levels at which an agentic workflow should be tested.
AI agent workflow testing is the systematic process of verifying that an AI agent correctly interprets inputs, selects tools, executes actions, maintains state, and produces acceptable outputs under expected and unexpected conditions.
Major testing levels include:
- Unit testing: Tests individual components such as prompt templates, parsers, memory modules, validators, and tool wrappers.
- Integration testing: Verifies interactions among the language model, tools, databases, APIs, and orchestration framework.
- Workflow testing: Evaluates complete multi-step paths, including planning, tool selection, retries, and termination.
- End-to-end testing: Tests the production-like system from user request to final response.
- Regression testing: Ensures that model, prompt, or code changes do not break previously successful behavior.
- Safety and adversarial testing: Checks resistance to prompt injection, unsafe tool usage, data leakage, and malicious inputs.
A good test suite combines deterministic assertions with semantic evaluation because AI outputs may vary while still being correct.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →